﻿USE [StoresManagement]


--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Addresses-Insert]    Script Date: [[20120714223923]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223923]]
-- Description:	Insert record into table [dbo].[Addresses]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Addresses-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Addresses-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Addresses-Insert]
	/*@Address_RowNumber int =Null OUTPUT , 
	@Address_ID uniqueidentifier =Null  , 
	@Address_Code varchar(50) =Null  , 
	@Country_ID uniqueidentifier =Null  , 
	@State_NameAr varchar(50) =Null  , 
	@State_NameEn varchar(50) =Null  , 
	@Town_NameAr varchar(50) =Null  , 
	@Town_NameEn varchar(50) =Null  , 
	@Address_NameAr varchar(50) =Null  , 
	@Address_NameEn varchar(50) =Null  , 
	@Postal_Code varchar(50) =Null  , 
	@Address_Notes varchar(max) =Null  , 
	@Address_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Addresses](/*[Address_ID], [Address_Code], [Country_ID], [State_NameAr], [State_NameEn], [Town_NameAr], [Town_NameEn], [Address_NameAr], [Address_NameEn], [Postal_Code], [Address_Notes], [Address_Search]*/)
	VALUES     (/*@Address_ID, @Address_Code, @Country_ID, @State_NameAr, @State_NameEn, @Town_NameAr, @Town_NameEn, @Address_NameAr, @Address_NameEn, @Postal_Code, @Address_Notes, @Address_Search*/)

	/*SELECT @Address_RowNumber = [Address_RowNumber]
    FROM [dbo].[Addresses]
    WHERE  ( [Address_ID] =@Address_ID )
	AND  ( [Address_Code] =@Address_Code )
	AND  ( [Country_ID] =@Country_ID )
	AND  ( [State_NameAr] =@State_NameAr )
	AND  ( [State_NameEn] =@State_NameEn )
	AND  ( [Town_NameAr] =@Town_NameAr )
	AND  ( [Town_NameEn] =@Town_NameEn )
	AND  ( [Address_NameAr] =@Address_NameAr )
	AND  ( [Address_NameEn] =@Address_NameEn )
	AND  ( [Postal_Code] =@Postal_Code )
	AND  ( [Address_Notes] =@Address_Notes )
	AND  ( [Address_Search] =@Address_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Addresses-update]    Script Date: [[20120714223923]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223923]]
-- Description:	Update record in table [dbo].[Addresses]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Addresses-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Addresses-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Addresses-update]
	/*@Address_RowNumber int =Null OUTPUT , 
	@Address_ID uniqueidentifier =Null  , 
	@Address_Code varchar(50) =Null  , 
	@Country_ID uniqueidentifier =Null  , 
	@State_NameAr varchar(50) =Null  , 
	@State_NameEn varchar(50) =Null  , 
	@Town_NameAr varchar(50) =Null  , 
	@Town_NameEn varchar(50) =Null  , 
	@Address_NameAr varchar(50) =Null  , 
	@Address_NameEn varchar(50) =Null  , 
	@Postal_Code varchar(50) =Null  , 
	@Address_Notes varchar(max) =Null  , 
	@Address_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Addresses] SET 
		/*[Address_ID] =@Address_ID, 
		[Address_Code] =@Address_Code, 
		[Country_ID] =@Country_ID, 
		[State_NameAr] =@State_NameAr, 
		[State_NameEn] =@State_NameEn, 
		[Town_NameAr] =@Town_NameAr, 
		[Town_NameEn] =@Town_NameEn, 
		[Address_NameAr] =@Address_NameAr, 
		[Address_NameEn] =@Address_NameEn, 
		[Postal_Code] =@Postal_Code, 
		[Address_Notes] =@Address_Notes, 
		[Address_Search] =@Address_Search*/
		/*WHERE ([Address_ID] = @Address_ID)*/
	/**/

	/*SELECT @Address_RowNumber = [Address_RowNumber]
    FROM [dbo].[Addresses]
	WHERE ([Address_ID] = @Address_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Addresses-Insert-Update]    Script Date: [[20120714223923]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223923]]
-- Description:	Insert OR Update record into table [dbo].[Addresses]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Addresses-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Addresses-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Addresses-Insert-Update]
	/*@Address_RowNumber int =Null OUTPUT , 
	@Address_ID uniqueidentifier =Null  , 
	@Address_Code varchar(50) =Null  , 
	@Country_ID uniqueidentifier =Null  , 
	@State_NameAr varchar(50) =Null  , 
	@State_NameEn varchar(50) =Null  , 
	@Town_NameAr varchar(50) =Null  , 
	@Town_NameEn varchar(50) =Null  , 
	@Address_NameAr varchar(50) =Null  , 
	@Address_NameEn varchar(50) =Null  , 
	@Postal_Code varchar(50) =Null  , 
	@Address_Notes varchar(max) =Null  , 
	@Address_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Addresses] 
					/*WHERE ([Address_ID] = @Address_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Addresses](/*[Address_ID], [Address_Code], [Country_ID], [State_NameAr], [State_NameEn], [Town_NameAr], [Town_NameEn], [Address_NameAr], [Address_NameEn], [Postal_Code], [Address_Notes], [Address_Search]*/)
		VALUES     (/*@Address_ID, @Address_Code, @Country_ID, @State_NameAr, @State_NameEn, @Town_NameAr, @Town_NameEn, @Address_NameAr, @Address_NameEn, @Postal_Code, @Address_Notes, @Address_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Addresses] SET 
			/*[Address_ID] =@Address_ID, 
			[Address_Code] =@Address_Code, 
			[Country_ID] =@Country_ID, 
			[State_NameAr] =@State_NameAr, 
			[State_NameEn] =@State_NameEn, 
			[Town_NameAr] =@Town_NameAr, 
			[Town_NameEn] =@Town_NameEn, 
			[Address_NameAr] =@Address_NameAr, 
			[Address_NameEn] =@Address_NameEn, 
			[Postal_Code] =@Postal_Code, 
			[Address_Notes] =@Address_Notes, 
			[Address_Search] =@Address_Search*/
			/*WHERE ([Address_ID] = @Address_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Address_RowNumber = [Address_RowNumber]
    FROM [dbo].[Addresses]
	WHERE ([Address_ID] = @Address_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Addresses-Delete]    Script Date: [[20120714223923]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223923]]
-- Description:	delete records from table [dbo].[Addresses] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Addresses-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Addresses-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Addresses-Delete]
	/*@Address_RowNumber int =null  , 
	@Address_ID uniqueidentifier =null  , 
	@Address_Code varchar(50) =null  , 
	@Country_ID uniqueidentifier =null  , 
	@State_NameAr varchar(50) =null  , 
	@State_NameEn varchar(50) =null  , 
	@Town_NameAr varchar(50) =null  , 
	@Town_NameEn varchar(50) =null  , 
	@Address_NameAr varchar(50) =null  , 
	@Address_NameEn varchar(50) =null  , 
	@Postal_Code varchar(50) =null  , 
	@Address_Notes varchar(max) =null  , 
	@Address_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Addresses]
	WHERE /*( [Address_RowNumber] = ISNULL(@Address_RowNumber, [Address_RowNumber]) )
	AND ( [Address_ID] = ISNULL(@Address_ID, [Address_ID]) )
	AND ( [Address_Code] like ISNULL(@Address_Code, [Address_Code]) )
	AND ( [Country_ID] = ISNULL(@Country_ID, [Country_ID]) )
	AND ( [State_NameAr] like ISNULL(@State_NameAr, [State_NameAr]) )
	AND ( [State_NameEn] like ISNULL(@State_NameEn, [State_NameEn]) )
	AND ( [Town_NameAr] like ISNULL(@Town_NameAr, [Town_NameAr]) )
	AND ( [Town_NameEn] like ISNULL(@Town_NameEn, [Town_NameEn]) )
	AND ( [Address_NameAr] like ISNULL(@Address_NameAr, [Address_NameAr]) )
	AND ( [Address_NameEn] like ISNULL(@Address_NameEn, [Address_NameEn]) )
	AND ( [Postal_Code] like ISNULL(@Postal_Code, [Postal_Code]) )
	AND ( [Address_Notes] like ISNULL(@Address_Notes, [Address_Notes]) )
	AND ( [Address_Search] like ISNULL(@Address_Search, [Address_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Addresses-Select]    Script Date: [[20120714223923]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223923]]
-- Description:	select records from table [dbo].[Addresses] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Addresses-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Addresses-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Addresses-Select]
	/*@Address_RowNumber int =null  , 
	@Address_ID uniqueidentifier =null  , 
	@Address_Code varchar(50) =null  , 
	@Country_ID uniqueidentifier =null  , 
	@State_NameAr varchar(50) =null  , 
	@State_NameEn varchar(50) =null  , 
	@Town_NameAr varchar(50) =null  , 
	@Town_NameEn varchar(50) =null  , 
	@Address_NameAr varchar(50) =null  , 
	@Address_NameEn varchar(50) =null  , 
	@Postal_Code varchar(50) =null  , 
	@Address_Notes varchar(max) =null  , 
	@Address_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Addresses]
	WHERE /*( [Address_RowNumber] = ISNULL(@Address_RowNumber, [Address_RowNumber]) )
	AND ( [Address_ID] = ISNULL(@Address_ID, [Address_ID]) )
	AND ( [Address_Code] like ISNULL(@Address_Code, [Address_Code]) )
	AND ( [Country_ID] = ISNULL(@Country_ID, [Country_ID]) )
	AND ( [State_NameAr] like ISNULL(@State_NameAr, [State_NameAr]) )
	AND ( [State_NameEn] like ISNULL(@State_NameEn, [State_NameEn]) )
	AND ( [Town_NameAr] like ISNULL(@Town_NameAr, [Town_NameAr]) )
	AND ( [Town_NameEn] like ISNULL(@Town_NameEn, [Town_NameEn]) )
	AND ( [Address_NameAr] like ISNULL(@Address_NameAr, [Address_NameAr]) )
	AND ( [Address_NameEn] like ISNULL(@Address_NameEn, [Address_NameEn]) )
	AND ( [Postal_Code] like ISNULL(@Postal_Code, [Postal_Code]) )
	AND ( [Address_Notes] like ISNULL(@Address_Notes, [Address_Notes]) )
	AND ( [Address_Search] like ISNULL(@Address_Search, [Address_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Banks-Insert]    Script Date: [[20120714223924]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223924]]
-- Description:	Insert record into table [dbo].[Banks]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Banks-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Banks-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Banks-Insert]
	/*@Bank_RowNumber int =Null OUTPUT , 
	@Bank_ID uniqueidentifier =Null  , 
	@Bank_ParentID uniqueidentifier =Null  , 
	@Bank_Code varchar(50) =Null  , 
	@Bank_NameAr varchar(300) =Null  , 
	@Bank_NameEn varchar(300) =Null  , 
	@Bank_Notes varchar(max) =Null  , 
	@Bank_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Banks](/*[Bank_ID], [Bank_ParentID], [Bank_Code], [Bank_NameAr], [Bank_NameEn], [Bank_Notes], [Bank_Search]*/)
	VALUES     (/*@Bank_ID, @Bank_ParentID, @Bank_Code, @Bank_NameAr, @Bank_NameEn, @Bank_Notes, @Bank_Search*/)

	/*SELECT @Bank_RowNumber = [Bank_RowNumber]
    FROM [dbo].[Banks]
    WHERE  ( [Bank_ID] =@Bank_ID )
	AND  ( [Bank_ParentID] =@Bank_ParentID )
	AND  ( [Bank_Code] =@Bank_Code )
	AND  ( [Bank_NameAr] =@Bank_NameAr )
	AND  ( [Bank_NameEn] =@Bank_NameEn )
	AND  ( [Bank_Notes] =@Bank_Notes )
	AND  ( [Bank_Search] =@Bank_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Banks-update]    Script Date: [[20120714223924]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223924]]
-- Description:	Update record in table [dbo].[Banks]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Banks-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Banks-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Banks-update]
	/*@Bank_RowNumber int =Null OUTPUT , 
	@Bank_ID uniqueidentifier =Null  , 
	@Bank_ParentID uniqueidentifier =Null  , 
	@Bank_Code varchar(50) =Null  , 
	@Bank_NameAr varchar(300) =Null  , 
	@Bank_NameEn varchar(300) =Null  , 
	@Bank_Notes varchar(max) =Null  , 
	@Bank_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Banks] SET 
		/*[Bank_ID] =@Bank_ID, 
		[Bank_ParentID] =@Bank_ParentID, 
		[Bank_Code] =@Bank_Code, 
		[Bank_NameAr] =@Bank_NameAr, 
		[Bank_NameEn] =@Bank_NameEn, 
		[Bank_Notes] =@Bank_Notes, 
		[Bank_Search] =@Bank_Search*/
		/*WHERE ([Bank_ID] = @Bank_ID)*/
	/**/

	/*SELECT @Bank_RowNumber = [Bank_RowNumber]
    FROM [dbo].[Banks]
	WHERE ([Bank_ID] = @Bank_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Banks-Insert-Update]    Script Date: [[20120714223924]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223924]]
-- Description:	Insert OR Update record into table [dbo].[Banks]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Banks-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Banks-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Banks-Insert-Update]
	/*@Bank_RowNumber int =Null OUTPUT , 
	@Bank_ID uniqueidentifier =Null  , 
	@Bank_ParentID uniqueidentifier =Null  , 
	@Bank_Code varchar(50) =Null  , 
	@Bank_NameAr varchar(300) =Null  , 
	@Bank_NameEn varchar(300) =Null  , 
	@Bank_Notes varchar(max) =Null  , 
	@Bank_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Banks] 
					/*WHERE ([Bank_ID] = @Bank_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Banks](/*[Bank_ID], [Bank_ParentID], [Bank_Code], [Bank_NameAr], [Bank_NameEn], [Bank_Notes], [Bank_Search]*/)
		VALUES     (/*@Bank_ID, @Bank_ParentID, @Bank_Code, @Bank_NameAr, @Bank_NameEn, @Bank_Notes, @Bank_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Banks] SET 
			/*[Bank_ID] =@Bank_ID, 
			[Bank_ParentID] =@Bank_ParentID, 
			[Bank_Code] =@Bank_Code, 
			[Bank_NameAr] =@Bank_NameAr, 
			[Bank_NameEn] =@Bank_NameEn, 
			[Bank_Notes] =@Bank_Notes, 
			[Bank_Search] =@Bank_Search*/
			/*WHERE ([Bank_ID] = @Bank_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Bank_RowNumber = [Bank_RowNumber]
    FROM [dbo].[Banks]
	WHERE ([Bank_ID] = @Bank_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Banks-Delete]    Script Date: [[20120714223924]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223924]]
-- Description:	delete records from table [dbo].[Banks] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Banks-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Banks-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Banks-Delete]
	/*@Bank_RowNumber int =null  , 
	@Bank_ID uniqueidentifier =null  , 
	@Bank_ParentID uniqueidentifier =null  , 
	@Bank_Code varchar(50) =null  , 
	@Bank_NameAr varchar(300) =null  , 
	@Bank_NameEn varchar(300) =null  , 
	@Bank_Notes varchar(max) =null  , 
	@Bank_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Banks]
	WHERE /*( [Bank_RowNumber] = ISNULL(@Bank_RowNumber, [Bank_RowNumber]) )
	AND ( [Bank_ID] = ISNULL(@Bank_ID, [Bank_ID]) )
	AND ( [Bank_ParentID] = ISNULL(@Bank_ParentID, [Bank_ParentID]) )
	AND ( [Bank_Code] like ISNULL(@Bank_Code, [Bank_Code]) )
	AND ( [Bank_NameAr] like ISNULL(@Bank_NameAr, [Bank_NameAr]) )
	AND ( [Bank_NameEn] like ISNULL(@Bank_NameEn, [Bank_NameEn]) )
	AND ( [Bank_Notes] like ISNULL(@Bank_Notes, [Bank_Notes]) )
	AND ( [Bank_Search] like ISNULL(@Bank_Search, [Bank_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Banks-Select]    Script Date: [[20120714223924]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223924]]
-- Description:	select records from table [dbo].[Banks] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Banks-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Banks-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Banks-Select]
	/*@Bank_RowNumber int =null  , 
	@Bank_ID uniqueidentifier =null  , 
	@Bank_ParentID uniqueidentifier =null  , 
	@Bank_Code varchar(50) =null  , 
	@Bank_NameAr varchar(300) =null  , 
	@Bank_NameEn varchar(300) =null  , 
	@Bank_Notes varchar(max) =null  , 
	@Bank_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Banks]
	WHERE /*( [Bank_RowNumber] = ISNULL(@Bank_RowNumber, [Bank_RowNumber]) )
	AND ( [Bank_ID] = ISNULL(@Bank_ID, [Bank_ID]) )
	AND ( [Bank_ParentID] = ISNULL(@Bank_ParentID, [Bank_ParentID]) )
	AND ( [Bank_Code] like ISNULL(@Bank_Code, [Bank_Code]) )
	AND ( [Bank_NameAr] like ISNULL(@Bank_NameAr, [Bank_NameAr]) )
	AND ( [Bank_NameEn] like ISNULL(@Bank_NameEn, [Bank_NameEn]) )
	AND ( [Bank_Notes] like ISNULL(@Bank_Notes, [Bank_Notes]) )
	AND ( [Bank_Search] like ISNULL(@Bank_Search, [Bank_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Bills-Insert]    Script Date: [[20120714223925]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223925]]
-- Description:	Insert record into table [dbo].[Bills]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Bills-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Bills-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Bills-Insert]
	/*@Bill_RowNumber int =Null OUTPUT , 
	@Bill_ID uniqueidentifier =Null  , 
	@Bill_Code varchar(50) =Null  , 
	@BillType_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Date datetime =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Bills](/*[Bill_ID], [Bill_Code], [BillType_ID], [Dealer_ID], [Date]*/)
	VALUES     (/*@Bill_ID, @Bill_Code, @BillType_ID, @Dealer_ID, @Date*/)

	/*SELECT @Bill_RowNumber = [Bill_RowNumber]
    FROM [dbo].[Bills]
    WHERE  ( [Bill_ID] =@Bill_ID )
	AND  ( [Bill_Code] =@Bill_Code )
	AND  ( [BillType_ID] =@BillType_ID )
	AND  ( [Dealer_ID] =@Dealer_ID )
	AND  ( [Date] =@Date )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Bills-update]    Script Date: [[20120714223925]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223925]]
-- Description:	Update record in table [dbo].[Bills]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Bills-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Bills-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Bills-update]
	/*@Bill_RowNumber int =Null OUTPUT , 
	@Bill_ID uniqueidentifier =Null  , 
	@Bill_Code varchar(50) =Null  , 
	@BillType_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Date datetime =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Bills] SET 
		/*[Bill_ID] =@Bill_ID, 
		[Bill_Code] =@Bill_Code, 
		[BillType_ID] =@BillType_ID, 
		[Dealer_ID] =@Dealer_ID, 
		[Date] =@Date*/
		/*WHERE ([Bill_ID] = @Bill_ID)*/
	/**/

	/*SELECT @Bill_RowNumber = [Bill_RowNumber]
    FROM [dbo].[Bills]
	WHERE ([Bill_ID] = @Bill_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Bills-Insert-Update]    Script Date: [[20120714223925]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223925]]
-- Description:	Insert OR Update record into table [dbo].[Bills]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Bills-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Bills-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Bills-Insert-Update]
	/*@Bill_RowNumber int =Null OUTPUT , 
	@Bill_ID uniqueidentifier =Null  , 
	@Bill_Code varchar(50) =Null  , 
	@BillType_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Date datetime =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Bills] 
					/*WHERE ([Bill_ID] = @Bill_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Bills](/*[Bill_ID], [Bill_Code], [BillType_ID], [Dealer_ID], [Date]*/)
		VALUES     (/*@Bill_ID, @Bill_Code, @BillType_ID, @Dealer_ID, @Date*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Bills] SET 
			/*[Bill_ID] =@Bill_ID, 
			[Bill_Code] =@Bill_Code, 
			[BillType_ID] =@BillType_ID, 
			[Dealer_ID] =@Dealer_ID, 
			[Date] =@Date*/
			/*WHERE ([Bill_ID] = @Bill_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Bill_RowNumber = [Bill_RowNumber]
    FROM [dbo].[Bills]
	WHERE ([Bill_ID] = @Bill_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Bills-Delete]    Script Date: [[20120714223925]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223925]]
-- Description:	delete records from table [dbo].[Bills] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Bills-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Bills-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Bills-Delete]
	/*@Bill_RowNumber int =null  , 
	@Bill_ID uniqueidentifier =null  , 
	@Bill_Code varchar(50) =null  , 
	@BillType_ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Date datetime =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Bills]
	WHERE /*( [Bill_RowNumber] = ISNULL(@Bill_RowNumber, [Bill_RowNumber]) )
	AND ( [Bill_ID] = ISNULL(@Bill_ID, [Bill_ID]) )
	AND ( [Bill_Code] like ISNULL(@Bill_Code, [Bill_Code]) )
	AND ( [BillType_ID] = ISNULL(@BillType_ID, [BillType_ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Date] = ISNULL(@Date, [Date]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Bills-Select]    Script Date: [[20120714223925]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223925]]
-- Description:	select records from table [dbo].[Bills] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Bills-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Bills-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Bills-Select]
	/*@Bill_RowNumber int =null  , 
	@Bill_ID uniqueidentifier =null  , 
	@Bill_Code varchar(50) =null  , 
	@BillType_ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Date datetime =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Bills]
	WHERE /*( [Bill_RowNumber] = ISNULL(@Bill_RowNumber, [Bill_RowNumber]) )
	AND ( [Bill_ID] = ISNULL(@Bill_ID, [Bill_ID]) )
	AND ( [Bill_Code] like ISNULL(@Bill_Code, [Bill_Code]) )
	AND ( [BillType_ID] = ISNULL(@BillType_ID, [BillType_ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Date] = ISNULL(@Date, [Date]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsDetails-Insert]    Script Date: [[20120714223926]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223926]]
-- Description:	Insert record into table [dbo].[BillsDetails]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsDetails-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsDetails-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsDetails-Insert]
	/*@BillDetail_RowNumber int =Null OUTPUT , 
	@BillDetail_ID uniqueidentifier =Null  , 
	@Bill_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Offer_ID uniqueidentifier =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Quantity float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@Price float =Null  , 
	@IsAdding tinyint =1*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[BillsDetails](/*[BillDetail_ID], [Bill_ID], [Product_ID], [Offer_ID], [Store_ID], [Quantity], [MeasureUnit_ID], [Price], [IsAdding]*/)
	VALUES     (/*@BillDetail_ID, @Bill_ID, @Product_ID, @Offer_ID, @Store_ID, @Quantity, @MeasureUnit_ID, @Price, @IsAdding*/)

	/*SELECT @BillDetail_RowNumber = [BillDetail_RowNumber]
    FROM [dbo].[BillsDetails]
    WHERE  ( [BillDetail_ID] =@BillDetail_ID )
	AND  ( [Bill_ID] =@Bill_ID )
	AND  ( [Product_ID] =@Product_ID )
	AND  ( [Offer_ID] =@Offer_ID )
	AND  ( [Store_ID] =@Store_ID )
	AND  ( [Quantity] =@Quantity )
	AND  ( [MeasureUnit_ID] =@MeasureUnit_ID )
	AND  ( [Price] =@Price )
	AND  ( [IsAdding] =@IsAdding )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsDetails-update]    Script Date: [[20120714223926]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223926]]
-- Description:	Update record in table [dbo].[BillsDetails]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsDetails-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsDetails-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsDetails-update]
	/*@BillDetail_RowNumber int =Null OUTPUT , 
	@BillDetail_ID uniqueidentifier =Null  , 
	@Bill_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Offer_ID uniqueidentifier =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Quantity float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@Price float =Null  , 
	@IsAdding tinyint =1*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[BillsDetails] SET 
		/*[BillDetail_ID] =@BillDetail_ID, 
		[Bill_ID] =@Bill_ID, 
		[Product_ID] =@Product_ID, 
		[Offer_ID] =@Offer_ID, 
		[Store_ID] =@Store_ID, 
		[Quantity] =@Quantity, 
		[MeasureUnit_ID] =@MeasureUnit_ID, 
		[Price] =@Price, 
		[IsAdding] =@IsAdding*/
		/*WHERE ([BillDetail_ID] = @BillDetail_ID)*/
	/**/

	/*SELECT @BillDetail_RowNumber = [BillDetail_RowNumber]
    FROM [dbo].[BillsDetails]
	WHERE ([BillDetail_ID] = @BillDetail_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsDetails-Insert-Update]    Script Date: [[20120714223926]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223926]]
-- Description:	Insert OR Update record into table [dbo].[BillsDetails]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsDetails-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsDetails-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsDetails-Insert-Update]
	/*@BillDetail_RowNumber int =Null OUTPUT , 
	@BillDetail_ID uniqueidentifier =Null  , 
	@Bill_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Offer_ID uniqueidentifier =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Quantity float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@Price float =Null  , 
	@IsAdding tinyint =1  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[BillsDetails] 
					/*WHERE ([BillDetail_ID] = @BillDetail_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[BillsDetails](/*[BillDetail_ID], [Bill_ID], [Product_ID], [Offer_ID], [Store_ID], [Quantity], [MeasureUnit_ID], [Price], [IsAdding]*/)
		VALUES     (/*@BillDetail_ID, @Bill_ID, @Product_ID, @Offer_ID, @Store_ID, @Quantity, @MeasureUnit_ID, @Price, @IsAdding*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[BillsDetails] SET 
			/*[BillDetail_ID] =@BillDetail_ID, 
			[Bill_ID] =@Bill_ID, 
			[Product_ID] =@Product_ID, 
			[Offer_ID] =@Offer_ID, 
			[Store_ID] =@Store_ID, 
			[Quantity] =@Quantity, 
			[MeasureUnit_ID] =@MeasureUnit_ID, 
			[Price] =@Price, 
			[IsAdding] =@IsAdding*/
			/*WHERE ([BillDetail_ID] = @BillDetail_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @BillDetail_RowNumber = [BillDetail_RowNumber]
    FROM [dbo].[BillsDetails]
	WHERE ([BillDetail_ID] = @BillDetail_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsDetails-Delete]    Script Date: [[20120714223926]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223926]]
-- Description:	delete records from table [dbo].[BillsDetails] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsDetails-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsDetails-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsDetails-Delete]
	/*@BillDetail_RowNumber int =null  , 
	@BillDetail_ID uniqueidentifier =null  , 
	@Bill_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Offer_ID uniqueidentifier =null  , 
	@Store_ID uniqueidentifier =null  , 
	@Quantity float =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@Price float =null  , 
	@IsAdding tinyint =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[BillsDetails]
	WHERE /*( [BillDetail_RowNumber] = ISNULL(@BillDetail_RowNumber, [BillDetail_RowNumber]) )
	AND ( [BillDetail_ID] = ISNULL(@BillDetail_ID, [BillDetail_ID]) )
	AND ( [Bill_ID] = ISNULL(@Bill_ID, [Bill_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Offer_ID] = ISNULL(@Offer_ID, [Offer_ID]) )
	AND ( [Store_ID] = ISNULL(@Store_ID, [Store_ID]) )
	AND ( [Quantity] = ISNULL(@Quantity, [Quantity]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [Price] = ISNULL(@Price, [Price]) )
	AND ( [IsAdding] = ISNULL(@IsAdding, [IsAdding]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsDetails-Select]    Script Date: [[20120714223926]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223926]]
-- Description:	select records from table [dbo].[BillsDetails] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsDetails-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsDetails-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsDetails-Select]
	/*@BillDetail_RowNumber int =null  , 
	@BillDetail_ID uniqueidentifier =null  , 
	@Bill_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Offer_ID uniqueidentifier =null  , 
	@Store_ID uniqueidentifier =null  , 
	@Quantity float =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@Price float =null  , 
	@IsAdding tinyint =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[BillsDetails]
	WHERE /*( [BillDetail_RowNumber] = ISNULL(@BillDetail_RowNumber, [BillDetail_RowNumber]) )
	AND ( [BillDetail_ID] = ISNULL(@BillDetail_ID, [BillDetail_ID]) )
	AND ( [Bill_ID] = ISNULL(@Bill_ID, [Bill_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Offer_ID] = ISNULL(@Offer_ID, [Offer_ID]) )
	AND ( [Store_ID] = ISNULL(@Store_ID, [Store_ID]) )
	AND ( [Quantity] = ISNULL(@Quantity, [Quantity]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [Price] = ISNULL(@Price, [Price]) )
	AND ( [IsAdding] = ISNULL(@IsAdding, [IsAdding]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsTypes-Insert]    Script Date: [[20120714223927]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223927]]
-- Description:	Insert record into table [dbo].[BillsTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsTypes-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsTypes-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsTypes-Insert]
	/*@BillType_RowNumber int =Null OUTPUT , 
	@BillType_ID uniqueidentifier =Null  , 
	@BillType_Code varchar(50) =Null  , 
	@BillType_NameAr varchar(300) =Null  , 
	@BillType_NameEn varchar(300) =Null  , 
	@BillType_Notes varchar(max) =Null  , 
	@BillType_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[BillsTypes](/*[BillType_ID], [BillType_Code], [BillType_NameAr], [BillType_NameEn], [BillType_Notes], [BillType_Search]*/)
	VALUES     (/*@BillType_ID, @BillType_Code, @BillType_NameAr, @BillType_NameEn, @BillType_Notes, @BillType_Search*/)

	/*SELECT @BillType_RowNumber = [BillType_RowNumber]
    FROM [dbo].[BillsTypes]
    WHERE  ( [BillType_ID] =@BillType_ID )
	AND  ( [BillType_Code] =@BillType_Code )
	AND  ( [BillType_NameAr] =@BillType_NameAr )
	AND  ( [BillType_NameEn] =@BillType_NameEn )
	AND  ( [BillType_Notes] =@BillType_Notes )
	AND  ( [BillType_Search] =@BillType_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsTypes-update]    Script Date: [[20120714223927]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223927]]
-- Description:	Update record in table [dbo].[BillsTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsTypes-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsTypes-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsTypes-update]
	/*@BillType_RowNumber int =Null OUTPUT , 
	@BillType_ID uniqueidentifier =Null  , 
	@BillType_Code varchar(50) =Null  , 
	@BillType_NameAr varchar(300) =Null  , 
	@BillType_NameEn varchar(300) =Null  , 
	@BillType_Notes varchar(max) =Null  , 
	@BillType_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[BillsTypes] SET 
		/*[BillType_ID] =@BillType_ID, 
		[BillType_Code] =@BillType_Code, 
		[BillType_NameAr] =@BillType_NameAr, 
		[BillType_NameEn] =@BillType_NameEn, 
		[BillType_Notes] =@BillType_Notes, 
		[BillType_Search] =@BillType_Search*/
		/*WHERE ([BillType_ID] = @BillType_ID)*/
	/**/

	/*SELECT @BillType_RowNumber = [BillType_RowNumber]
    FROM [dbo].[BillsTypes]
	WHERE ([BillType_ID] = @BillType_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsTypes-Insert-Update]    Script Date: [[20120714223927]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223927]]
-- Description:	Insert OR Update record into table [dbo].[BillsTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsTypes-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsTypes-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsTypes-Insert-Update]
	/*@BillType_RowNumber int =Null OUTPUT , 
	@BillType_ID uniqueidentifier =Null  , 
	@BillType_Code varchar(50) =Null  , 
	@BillType_NameAr varchar(300) =Null  , 
	@BillType_NameEn varchar(300) =Null  , 
	@BillType_Notes varchar(max) =Null  , 
	@BillType_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[BillsTypes] 
					/*WHERE ([BillType_ID] = @BillType_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[BillsTypes](/*[BillType_ID], [BillType_Code], [BillType_NameAr], [BillType_NameEn], [BillType_Notes], [BillType_Search]*/)
		VALUES     (/*@BillType_ID, @BillType_Code, @BillType_NameAr, @BillType_NameEn, @BillType_Notes, @BillType_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[BillsTypes] SET 
			/*[BillType_ID] =@BillType_ID, 
			[BillType_Code] =@BillType_Code, 
			[BillType_NameAr] =@BillType_NameAr, 
			[BillType_NameEn] =@BillType_NameEn, 
			[BillType_Notes] =@BillType_Notes, 
			[BillType_Search] =@BillType_Search*/
			/*WHERE ([BillType_ID] = @BillType_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @BillType_RowNumber = [BillType_RowNumber]
    FROM [dbo].[BillsTypes]
	WHERE ([BillType_ID] = @BillType_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsTypes-Delete]    Script Date: [[20120714223927]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223927]]
-- Description:	delete records from table [dbo].[BillsTypes] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsTypes-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsTypes-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsTypes-Delete]
	/*@BillType_RowNumber int =null  , 
	@BillType_ID uniqueidentifier =null  , 
	@BillType_Code varchar(50) =null  , 
	@BillType_NameAr varchar(300) =null  , 
	@BillType_NameEn varchar(300) =null  , 
	@BillType_Notes varchar(max) =null  , 
	@BillType_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[BillsTypes]
	WHERE /*( [BillType_RowNumber] = ISNULL(@BillType_RowNumber, [BillType_RowNumber]) )
	AND ( [BillType_ID] = ISNULL(@BillType_ID, [BillType_ID]) )
	AND ( [BillType_Code] like ISNULL(@BillType_Code, [BillType_Code]) )
	AND ( [BillType_NameAr] like ISNULL(@BillType_NameAr, [BillType_NameAr]) )
	AND ( [BillType_NameEn] like ISNULL(@BillType_NameEn, [BillType_NameEn]) )
	AND ( [BillType_Notes] like ISNULL(@BillType_Notes, [BillType_Notes]) )
	AND ( [BillType_Search] like ISNULL(@BillType_Search, [BillType_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[BillsTypes-Select]    Script Date: [[20120714223927]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223927]]
-- Description:	select records from table [dbo].[BillsTypes] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[BillsTypes-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[BillsTypes-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[BillsTypes-Select]
	/*@BillType_RowNumber int =null  , 
	@BillType_ID uniqueidentifier =null  , 
	@BillType_Code varchar(50) =null  , 
	@BillType_NameAr varchar(300) =null  , 
	@BillType_NameEn varchar(300) =null  , 
	@BillType_Notes varchar(max) =null  , 
	@BillType_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[BillsTypes]
	WHERE /*( [BillType_RowNumber] = ISNULL(@BillType_RowNumber, [BillType_RowNumber]) )
	AND ( [BillType_ID] = ISNULL(@BillType_ID, [BillType_ID]) )
	AND ( [BillType_Code] like ISNULL(@BillType_Code, [BillType_Code]) )
	AND ( [BillType_NameAr] like ISNULL(@BillType_NameAr, [BillType_NameAr]) )
	AND ( [BillType_NameEn] like ISNULL(@BillType_NameEn, [BillType_NameEn]) )
	AND ( [BillType_Notes] like ISNULL(@BillType_Notes, [BillType_Notes]) )
	AND ( [BillType_Search] like ISNULL(@BillType_Search, [BillType_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactPersonsContacts-Insert]    Script Date: [[20120714223927]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223927]]
-- Description:	Insert record into table [dbo].[ContactPersonsContacts]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactPersonsContacts-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactPersonsContacts-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactPersonsContacts-Insert]
	/*@PersonContact_RowNumber int =Null OUTPUT , 
	@PersonContact_ID uniqueidentifier =Null  , 
	@Person_ID uniqueidentifier =Null  , 
	@ContactType_ID uniqueidentifier =Null  , 
	@Contact_Value varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[ContactPersonsContacts](/*[PersonContact_ID], [Person_ID], [ContactType_ID], [Contact_Value]*/)
	VALUES     (/*@PersonContact_ID, @Person_ID, @ContactType_ID, @Contact_Value*/)

	/*SELECT @PersonContact_RowNumber = [PersonContact_RowNumber]
    FROM [dbo].[ContactPersonsContacts]
    WHERE  ( [PersonContact_ID] =@PersonContact_ID )
	AND  ( [Person_ID] =@Person_ID )
	AND  ( [ContactType_ID] =@ContactType_ID )
	AND  ( [Contact_Value] =@Contact_Value )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactPersonsContacts-update]    Script Date: [[20120714223927]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223927]]
-- Description:	Update record in table [dbo].[ContactPersonsContacts]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactPersonsContacts-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactPersonsContacts-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactPersonsContacts-update]
	/*@PersonContact_RowNumber int =Null OUTPUT , 
	@PersonContact_ID uniqueidentifier =Null  , 
	@Person_ID uniqueidentifier =Null  , 
	@ContactType_ID uniqueidentifier =Null  , 
	@Contact_Value varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[ContactPersonsContacts] SET 
		/*[PersonContact_ID] =@PersonContact_ID, 
		[Person_ID] =@Person_ID, 
		[ContactType_ID] =@ContactType_ID, 
		[Contact_Value] =@Contact_Value*/
		/*WHERE ([PersonContact_ID] = @PersonContact_ID)*/
	/**/

	/*SELECT @PersonContact_RowNumber = [PersonContact_RowNumber]
    FROM [dbo].[ContactPersonsContacts]
	WHERE ([PersonContact_ID] = @PersonContact_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactPersonsContacts-Insert-Update]    Script Date: [[20120714223927]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223927]]
-- Description:	Insert OR Update record into table [dbo].[ContactPersonsContacts]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactPersonsContacts-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactPersonsContacts-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactPersonsContacts-Insert-Update]
	/*@PersonContact_RowNumber int =Null OUTPUT , 
	@PersonContact_ID uniqueidentifier =Null  , 
	@Person_ID uniqueidentifier =Null  , 
	@ContactType_ID uniqueidentifier =Null  , 
	@Contact_Value varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[ContactPersonsContacts] 
					/*WHERE ([PersonContact_ID] = @PersonContact_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[ContactPersonsContacts](/*[PersonContact_ID], [Person_ID], [ContactType_ID], [Contact_Value]*/)
		VALUES     (/*@PersonContact_ID, @Person_ID, @ContactType_ID, @Contact_Value*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[ContactPersonsContacts] SET 
			/*[PersonContact_ID] =@PersonContact_ID, 
			[Person_ID] =@Person_ID, 
			[ContactType_ID] =@ContactType_ID, 
			[Contact_Value] =@Contact_Value*/
			/*WHERE ([PersonContact_ID] = @PersonContact_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @PersonContact_RowNumber = [PersonContact_RowNumber]
    FROM [dbo].[ContactPersonsContacts]
	WHERE ([PersonContact_ID] = @PersonContact_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactPersonsContacts-Delete]    Script Date: [[20120714223927]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223927]]
-- Description:	delete records from table [dbo].[ContactPersonsContacts] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactPersonsContacts-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactPersonsContacts-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactPersonsContacts-Delete]
	/*@PersonContact_RowNumber int =null  , 
	@PersonContact_ID uniqueidentifier =null  , 
	@Person_ID uniqueidentifier =null  , 
	@ContactType_ID uniqueidentifier =null  , 
	@Contact_Value varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[ContactPersonsContacts]
	WHERE /*( [PersonContact_RowNumber] = ISNULL(@PersonContact_RowNumber, [PersonContact_RowNumber]) )
	AND ( [PersonContact_ID] = ISNULL(@PersonContact_ID, [PersonContact_ID]) )
	AND ( [Person_ID] = ISNULL(@Person_ID, [Person_ID]) )
	AND ( [ContactType_ID] = ISNULL(@ContactType_ID, [ContactType_ID]) )
	AND ( [Contact_Value] like ISNULL(@Contact_Value, [Contact_Value]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactPersonsContacts-Select]    Script Date: [[20120714223927]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223927]]
-- Description:	select records from table [dbo].[ContactPersonsContacts] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactPersonsContacts-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactPersonsContacts-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactPersonsContacts-Select]
	/*@PersonContact_RowNumber int =null  , 
	@PersonContact_ID uniqueidentifier =null  , 
	@Person_ID uniqueidentifier =null  , 
	@ContactType_ID uniqueidentifier =null  , 
	@Contact_Value varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[ContactPersonsContacts]
	WHERE /*( [PersonContact_RowNumber] = ISNULL(@PersonContact_RowNumber, [PersonContact_RowNumber]) )
	AND ( [PersonContact_ID] = ISNULL(@PersonContact_ID, [PersonContact_ID]) )
	AND ( [Person_ID] = ISNULL(@Person_ID, [Person_ID]) )
	AND ( [ContactType_ID] = ISNULL(@ContactType_ID, [ContactType_ID]) )
	AND ( [Contact_Value] like ISNULL(@Contact_Value, [Contact_Value]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactTypes-Insert]    Script Date: [[20120714223928]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223928]]
-- Description:	Insert record into table [dbo].[ContactTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactTypes-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactTypes-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactTypes-Insert]
	/*@ContactType_RowNumber int =Null OUTPUT , 
	@ContactType_ID uniqueidentifier =Null  , 
	@ContactType_Code varchar(50) =Null  , 
	@ContactType_NameAr varchar(300) =Null  , 
	@ContactType_NameEn varchar(300) =Null  , 
	@ContactType_Notes varchar(max) =Null  , 
	@ContactType_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[ContactTypes](/*[ContactType_ID], [ContactType_Code], [ContactType_NameAr], [ContactType_NameEn], [ContactType_Notes], [ContactType_Search]*/)
	VALUES     (/*@ContactType_ID, @ContactType_Code, @ContactType_NameAr, @ContactType_NameEn, @ContactType_Notes, @ContactType_Search*/)

	/*SELECT @ContactType_RowNumber = [ContactType_RowNumber]
    FROM [dbo].[ContactTypes]
    WHERE  ( [ContactType_ID] =@ContactType_ID )
	AND  ( [ContactType_Code] =@ContactType_Code )
	AND  ( [ContactType_NameAr] =@ContactType_NameAr )
	AND  ( [ContactType_NameEn] =@ContactType_NameEn )
	AND  ( [ContactType_Notes] =@ContactType_Notes )
	AND  ( [ContactType_Search] =@ContactType_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactTypes-update]    Script Date: [[20120714223928]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223928]]
-- Description:	Update record in table [dbo].[ContactTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactTypes-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactTypes-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactTypes-update]
	/*@ContactType_RowNumber int =Null OUTPUT , 
	@ContactType_ID uniqueidentifier =Null  , 
	@ContactType_Code varchar(50) =Null  , 
	@ContactType_NameAr varchar(300) =Null  , 
	@ContactType_NameEn varchar(300) =Null  , 
	@ContactType_Notes varchar(max) =Null  , 
	@ContactType_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[ContactTypes] SET 
		/*[ContactType_ID] =@ContactType_ID, 
		[ContactType_Code] =@ContactType_Code, 
		[ContactType_NameAr] =@ContactType_NameAr, 
		[ContactType_NameEn] =@ContactType_NameEn, 
		[ContactType_Notes] =@ContactType_Notes, 
		[ContactType_Search] =@ContactType_Search*/
		/*WHERE ([ContactType_ID] = @ContactType_ID)*/
	/**/

	/*SELECT @ContactType_RowNumber = [ContactType_RowNumber]
    FROM [dbo].[ContactTypes]
	WHERE ([ContactType_ID] = @ContactType_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactTypes-Insert-Update]    Script Date: [[20120714223928]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223928]]
-- Description:	Insert OR Update record into table [dbo].[ContactTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactTypes-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactTypes-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactTypes-Insert-Update]
	/*@ContactType_RowNumber int =Null OUTPUT , 
	@ContactType_ID uniqueidentifier =Null  , 
	@ContactType_Code varchar(50) =Null  , 
	@ContactType_NameAr varchar(300) =Null  , 
	@ContactType_NameEn varchar(300) =Null  , 
	@ContactType_Notes varchar(max) =Null  , 
	@ContactType_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[ContactTypes] 
					/*WHERE ([ContactType_ID] = @ContactType_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[ContactTypes](/*[ContactType_ID], [ContactType_Code], [ContactType_NameAr], [ContactType_NameEn], [ContactType_Notes], [ContactType_Search]*/)
		VALUES     (/*@ContactType_ID, @ContactType_Code, @ContactType_NameAr, @ContactType_NameEn, @ContactType_Notes, @ContactType_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[ContactTypes] SET 
			/*[ContactType_ID] =@ContactType_ID, 
			[ContactType_Code] =@ContactType_Code, 
			[ContactType_NameAr] =@ContactType_NameAr, 
			[ContactType_NameEn] =@ContactType_NameEn, 
			[ContactType_Notes] =@ContactType_Notes, 
			[ContactType_Search] =@ContactType_Search*/
			/*WHERE ([ContactType_ID] = @ContactType_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @ContactType_RowNumber = [ContactType_RowNumber]
    FROM [dbo].[ContactTypes]
	WHERE ([ContactType_ID] = @ContactType_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactTypes-Delete]    Script Date: [[20120714223928]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223928]]
-- Description:	delete records from table [dbo].[ContactTypes] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactTypes-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactTypes-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactTypes-Delete]
	/*@ContactType_RowNumber int =null  , 
	@ContactType_ID uniqueidentifier =null  , 
	@ContactType_Code varchar(50) =null  , 
	@ContactType_NameAr varchar(300) =null  , 
	@ContactType_NameEn varchar(300) =null  , 
	@ContactType_Notes varchar(max) =null  , 
	@ContactType_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[ContactTypes]
	WHERE /*( [ContactType_RowNumber] = ISNULL(@ContactType_RowNumber, [ContactType_RowNumber]) )
	AND ( [ContactType_ID] = ISNULL(@ContactType_ID, [ContactType_ID]) )
	AND ( [ContactType_Code] like ISNULL(@ContactType_Code, [ContactType_Code]) )
	AND ( [ContactType_NameAr] like ISNULL(@ContactType_NameAr, [ContactType_NameAr]) )
	AND ( [ContactType_NameEn] like ISNULL(@ContactType_NameEn, [ContactType_NameEn]) )
	AND ( [ContactType_Notes] like ISNULL(@ContactType_Notes, [ContactType_Notes]) )
	AND ( [ContactType_Search] like ISNULL(@ContactType_Search, [ContactType_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactTypes-Select]    Script Date: [[20120714223928]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223928]]
-- Description:	select records from table [dbo].[ContactTypes] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactTypes-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactTypes-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactTypes-Select]
	/*@ContactType_RowNumber int =null  , 
	@ContactType_ID uniqueidentifier =null  , 
	@ContactType_Code varchar(50) =null  , 
	@ContactType_NameAr varchar(300) =null  , 
	@ContactType_NameEn varchar(300) =null  , 
	@ContactType_Notes varchar(max) =null  , 
	@ContactType_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[ContactTypes]
	WHERE /*( [ContactType_RowNumber] = ISNULL(@ContactType_RowNumber, [ContactType_RowNumber]) )
	AND ( [ContactType_ID] = ISNULL(@ContactType_ID, [ContactType_ID]) )
	AND ( [ContactType_Code] like ISNULL(@ContactType_Code, [ContactType_Code]) )
	AND ( [ContactType_NameAr] like ISNULL(@ContactType_NameAr, [ContactType_NameAr]) )
	AND ( [ContactType_NameEn] like ISNULL(@ContactType_NameEn, [ContactType_NameEn]) )
	AND ( [ContactType_Notes] like ISNULL(@ContactType_Notes, [ContactType_Notes]) )
	AND ( [ContactType_Search] like ISNULL(@ContactType_Search, [ContactType_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Countries-Insert]    Script Date: [[20120714223928]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223928]]
-- Description:	Insert record into table [dbo].[Countries]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Countries-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Countries-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Countries-Insert]
	/*@Country_RowNumber int =Null OUTPUT , 
	@Country_ID uniqueidentifier =Null  , 
	@Country_Code varchar(50) =Null  , 
	@Country_NameAr varchar(300) =Null  , 
	@Country_NameEn varchar(300) =Null  , 
	@Country_Notes varchar(max) =Null  , 
	@Country_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Countries](/*[Country_ID], [Country_Code], [Country_NameAr], [Country_NameEn], [Country_Notes], [Country_Search]*/)
	VALUES     (/*@Country_ID, @Country_Code, @Country_NameAr, @Country_NameEn, @Country_Notes, @Country_Search*/)

	/*SELECT @Country_RowNumber = [Country_RowNumber]
    FROM [dbo].[Countries]
    WHERE  ( [Country_ID] =@Country_ID )
	AND  ( [Country_Code] =@Country_Code )
	AND  ( [Country_NameAr] =@Country_NameAr )
	AND  ( [Country_NameEn] =@Country_NameEn )
	AND  ( [Country_Notes] =@Country_Notes )
	AND  ( [Country_Search] =@Country_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Countries-update]    Script Date: [[20120714223929]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223929]]
-- Description:	Update record in table [dbo].[Countries]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Countries-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Countries-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Countries-update]
	/*@Country_RowNumber int =Null OUTPUT , 
	@Country_ID uniqueidentifier =Null  , 
	@Country_Code varchar(50) =Null  , 
	@Country_NameAr varchar(300) =Null  , 
	@Country_NameEn varchar(300) =Null  , 
	@Country_Notes varchar(max) =Null  , 
	@Country_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Countries] SET 
		/*[Country_ID] =@Country_ID, 
		[Country_Code] =@Country_Code, 
		[Country_NameAr] =@Country_NameAr, 
		[Country_NameEn] =@Country_NameEn, 
		[Country_Notes] =@Country_Notes, 
		[Country_Search] =@Country_Search*/
		/*WHERE ([Country_ID] = @Country_ID)*/
	/**/

	/*SELECT @Country_RowNumber = [Country_RowNumber]
    FROM [dbo].[Countries]
	WHERE ([Country_ID] = @Country_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Countries-Insert-Update]    Script Date: [[20120714223929]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223929]]
-- Description:	Insert OR Update record into table [dbo].[Countries]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Countries-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Countries-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Countries-Insert-Update]
	/*@Country_RowNumber int =Null OUTPUT , 
	@Country_ID uniqueidentifier =Null  , 
	@Country_Code varchar(50) =Null  , 
	@Country_NameAr varchar(300) =Null  , 
	@Country_NameEn varchar(300) =Null  , 
	@Country_Notes varchar(max) =Null  , 
	@Country_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Countries] 
					/*WHERE ([Country_ID] = @Country_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Countries](/*[Country_ID], [Country_Code], [Country_NameAr], [Country_NameEn], [Country_Notes], [Country_Search]*/)
		VALUES     (/*@Country_ID, @Country_Code, @Country_NameAr, @Country_NameEn, @Country_Notes, @Country_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Countries] SET 
			/*[Country_ID] =@Country_ID, 
			[Country_Code] =@Country_Code, 
			[Country_NameAr] =@Country_NameAr, 
			[Country_NameEn] =@Country_NameEn, 
			[Country_Notes] =@Country_Notes, 
			[Country_Search] =@Country_Search*/
			/*WHERE ([Country_ID] = @Country_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Country_RowNumber = [Country_RowNumber]
    FROM [dbo].[Countries]
	WHERE ([Country_ID] = @Country_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Countries-Delete]    Script Date: [[20120714223929]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223929]]
-- Description:	delete records from table [dbo].[Countries] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Countries-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Countries-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Countries-Delete]
	/*@Country_RowNumber int =null  , 
	@Country_ID uniqueidentifier =null  , 
	@Country_Code varchar(50) =null  , 
	@Country_NameAr varchar(300) =null  , 
	@Country_NameEn varchar(300) =null  , 
	@Country_Notes varchar(max) =null  , 
	@Country_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Countries]
	WHERE /*( [Country_RowNumber] = ISNULL(@Country_RowNumber, [Country_RowNumber]) )
	AND ( [Country_ID] = ISNULL(@Country_ID, [Country_ID]) )
	AND ( [Country_Code] like ISNULL(@Country_Code, [Country_Code]) )
	AND ( [Country_NameAr] like ISNULL(@Country_NameAr, [Country_NameAr]) )
	AND ( [Country_NameEn] like ISNULL(@Country_NameEn, [Country_NameEn]) )
	AND ( [Country_Notes] like ISNULL(@Country_Notes, [Country_Notes]) )
	AND ( [Country_Search] like ISNULL(@Country_Search, [Country_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Countries-Select]    Script Date: [[20120714223929]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223929]]
-- Description:	select records from table [dbo].[Countries] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Countries-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Countries-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Countries-Select]
	/*@Country_RowNumber int =null  , 
	@Country_ID uniqueidentifier =null  , 
	@Country_Code varchar(50) =null  , 
	@Country_NameAr varchar(300) =null  , 
	@Country_NameEn varchar(300) =null  , 
	@Country_Notes varchar(max) =null  , 
	@Country_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Countries]
	WHERE /*( [Country_RowNumber] = ISNULL(@Country_RowNumber, [Country_RowNumber]) )
	AND ( [Country_ID] = ISNULL(@Country_ID, [Country_ID]) )
	AND ( [Country_Code] like ISNULL(@Country_Code, [Country_Code]) )
	AND ( [Country_NameAr] like ISNULL(@Country_NameAr, [Country_NameAr]) )
	AND ( [Country_NameEn] like ISNULL(@Country_NameEn, [Country_NameEn]) )
	AND ( [Country_Notes] like ISNULL(@Country_Notes, [Country_Notes]) )
	AND ( [Country_Search] like ISNULL(@Country_Search, [Country_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers-Insert]    Script Date: [[20120714223929]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223929]]
-- Description:	Insert record into table [dbo].[Dealers]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers-Insert]
	/*@Dealer_RowNumber int =Null OUTPUT , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Dealer_Code varchar(50) =Null  , 
	@DealerType_ID uniqueidentifier =Null  , 
	@Dealer_NameAr varchar(300) =Null  , 
	@Dealer_NameEn varchar(300) =Null  , 
	@Dealer_Notes varchar(max) =Null  , 
	@Dealer_StartDate datetime =Null  , 
	@Dealer_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Dealers](/*[Dealer_ID], [Dealer_Code], [DealerType_ID], [Dealer_NameAr], [Dealer_NameEn], [Dealer_Notes], [Dealer_StartDate], [Dealer_Search]*/)
	VALUES     (/*@Dealer_ID, @Dealer_Code, @DealerType_ID, @Dealer_NameAr, @Dealer_NameEn, @Dealer_Notes, @Dealer_StartDate, @Dealer_Search*/)

	/*SELECT @Dealer_RowNumber = [Dealer_RowNumber]
    FROM [dbo].[Dealers]
    WHERE  ( [Dealer_ID] =@Dealer_ID )
	AND  ( [Dealer_Code] =@Dealer_Code )
	AND  ( [DealerType_ID] =@DealerType_ID )
	AND  ( [Dealer_NameAr] =@Dealer_NameAr )
	AND  ( [Dealer_NameEn] =@Dealer_NameEn )
	AND  ( [Dealer_Notes] =@Dealer_Notes )
	AND  ( [Dealer_StartDate] =@Dealer_StartDate )
	AND  ( [Dealer_Search] =@Dealer_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers-update]    Script Date: [[20120714223929]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223929]]
-- Description:	Update record in table [dbo].[Dealers]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers-update]
	/*@Dealer_RowNumber int =Null OUTPUT , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Dealer_Code varchar(50) =Null  , 
	@DealerType_ID uniqueidentifier =Null  , 
	@Dealer_NameAr varchar(300) =Null  , 
	@Dealer_NameEn varchar(300) =Null  , 
	@Dealer_Notes varchar(max) =Null  , 
	@Dealer_StartDate datetime =Null  , 
	@Dealer_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Dealers] SET 
		/*[Dealer_ID] =@Dealer_ID, 
		[Dealer_Code] =@Dealer_Code, 
		[DealerType_ID] =@DealerType_ID, 
		[Dealer_NameAr] =@Dealer_NameAr, 
		[Dealer_NameEn] =@Dealer_NameEn, 
		[Dealer_Notes] =@Dealer_Notes, 
		[Dealer_StartDate] =@Dealer_StartDate, 
		[Dealer_Search] =@Dealer_Search*/
		/*WHERE ([Dealer_ID] = @Dealer_ID)*/
	/**/

	/*SELECT @Dealer_RowNumber = [Dealer_RowNumber]
    FROM [dbo].[Dealers]
	WHERE ([Dealer_ID] = @Dealer_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers-Insert-Update]    Script Date: [[20120714223929]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223929]]
-- Description:	Insert OR Update record into table [dbo].[Dealers]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers-Insert-Update]
	/*@Dealer_RowNumber int =Null OUTPUT , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Dealer_Code varchar(50) =Null  , 
	@DealerType_ID uniqueidentifier =Null  , 
	@Dealer_NameAr varchar(300) =Null  , 
	@Dealer_NameEn varchar(300) =Null  , 
	@Dealer_Notes varchar(max) =Null  , 
	@Dealer_StartDate datetime =Null  , 
	@Dealer_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Dealers] 
					/*WHERE ([Dealer_ID] = @Dealer_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Dealers](/*[Dealer_ID], [Dealer_Code], [DealerType_ID], [Dealer_NameAr], [Dealer_NameEn], [Dealer_Notes], [Dealer_StartDate], [Dealer_Search]*/)
		VALUES     (/*@Dealer_ID, @Dealer_Code, @DealerType_ID, @Dealer_NameAr, @Dealer_NameEn, @Dealer_Notes, @Dealer_StartDate, @Dealer_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Dealers] SET 
			/*[Dealer_ID] =@Dealer_ID, 
			[Dealer_Code] =@Dealer_Code, 
			[DealerType_ID] =@DealerType_ID, 
			[Dealer_NameAr] =@Dealer_NameAr, 
			[Dealer_NameEn] =@Dealer_NameEn, 
			[Dealer_Notes] =@Dealer_Notes, 
			[Dealer_StartDate] =@Dealer_StartDate, 
			[Dealer_Search] =@Dealer_Search*/
			/*WHERE ([Dealer_ID] = @Dealer_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Dealer_RowNumber = [Dealer_RowNumber]
    FROM [dbo].[Dealers]
	WHERE ([Dealer_ID] = @Dealer_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers-Delete]    Script Date: [[20120714223929]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223929]]
-- Description:	delete records from table [dbo].[Dealers] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers-Delete]
	/*@Dealer_RowNumber int =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Dealer_Code varchar(50) =null  , 
	@DealerType_ID uniqueidentifier =null  , 
	@Dealer_NameAr varchar(300) =null  , 
	@Dealer_NameEn varchar(300) =null  , 
	@Dealer_Notes varchar(max) =null  , 
	@Dealer_StartDate datetime =null  , 
	@Dealer_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Dealers]
	WHERE /*( [Dealer_RowNumber] = ISNULL(@Dealer_RowNumber, [Dealer_RowNumber]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Dealer_Code] like ISNULL(@Dealer_Code, [Dealer_Code]) )
	AND ( [DealerType_ID] = ISNULL(@DealerType_ID, [DealerType_ID]) )
	AND ( [Dealer_NameAr] like ISNULL(@Dealer_NameAr, [Dealer_NameAr]) )
	AND ( [Dealer_NameEn] like ISNULL(@Dealer_NameEn, [Dealer_NameEn]) )
	AND ( [Dealer_Notes] like ISNULL(@Dealer_Notes, [Dealer_Notes]) )
	AND ( [Dealer_StartDate] = ISNULL(@Dealer_StartDate, [Dealer_StartDate]) )
	AND ( [Dealer_Search] like ISNULL(@Dealer_Search, [Dealer_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers-Select]    Script Date: [[20120714223929]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223929]]
-- Description:	select records from table [dbo].[Dealers] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers-Select]
	/*@Dealer_RowNumber int =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Dealer_Code varchar(50) =null  , 
	@DealerType_ID uniqueidentifier =null  , 
	@Dealer_NameAr varchar(300) =null  , 
	@Dealer_NameEn varchar(300) =null  , 
	@Dealer_Notes varchar(max) =null  , 
	@Dealer_StartDate datetime =null  , 
	@Dealer_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Dealers]
	WHERE /*( [Dealer_RowNumber] = ISNULL(@Dealer_RowNumber, [Dealer_RowNumber]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Dealer_Code] like ISNULL(@Dealer_Code, [Dealer_Code]) )
	AND ( [DealerType_ID] = ISNULL(@DealerType_ID, [DealerType_ID]) )
	AND ( [Dealer_NameAr] like ISNULL(@Dealer_NameAr, [Dealer_NameAr]) )
	AND ( [Dealer_NameEn] like ISNULL(@Dealer_NameEn, [Dealer_NameEn]) )
	AND ( [Dealer_Notes] like ISNULL(@Dealer_Notes, [Dealer_Notes]) )
	AND ( [Dealer_StartDate] = ISNULL(@Dealer_StartDate, [Dealer_StartDate]) )
	AND ( [Dealer_Search] like ISNULL(@Dealer_Search, [Dealer_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Addresses-Insert]    Script Date: [[20120714223930]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223930]]
-- Description:	Insert record into table [dbo].[Dealers_Addresses]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Addresses-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Addresses-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Addresses-Insert]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Address_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Dealers_Addresses](/*[ID], [Dealer_ID], [Address_ID]*/)
	VALUES     (/*@ID, @Dealer_ID, @Address_ID*/)

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Dealers_Addresses]
    WHERE  ( [ID] =@ID )
	AND  ( [Dealer_ID] =@Dealer_ID )
	AND  ( [Address_ID] =@Address_ID )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Addresses-update]    Script Date: [[20120714223930]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223930]]
-- Description:	Update record in table [dbo].[Dealers_Addresses]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Addresses-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Addresses-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Addresses-update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Address_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Dealers_Addresses] SET 
		/*[ID] =@ID, 
		[Dealer_ID] =@Dealer_ID, 
		[Address_ID] =@Address_ID*/
		/*WHERE ([ID] = @ID)*/
	/**/

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Dealers_Addresses]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Addresses-Insert-Update]    Script Date: [[20120714223930]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223930]]
-- Description:	Insert OR Update record into table [dbo].[Dealers_Addresses]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Addresses-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Addresses-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Addresses-Insert-Update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Address_ID uniqueidentifier =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Dealers_Addresses] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Dealers_Addresses](/*[ID], [Dealer_ID], [Address_ID]*/)
		VALUES     (/*@ID, @Dealer_ID, @Address_ID*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Dealers_Addresses] SET 
			/*[ID] =@ID, 
			[Dealer_ID] =@Dealer_ID, 
			[Address_ID] =@Address_ID*/
			/*WHERE ([ID] = @ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Dealers_Addresses]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Addresses-Delete]    Script Date: [[20120714223930]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223930]]
-- Description:	delete records from table [dbo].[Dealers_Addresses] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Addresses-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Addresses-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Addresses-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Address_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Dealers_Addresses]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Address_ID] = ISNULL(@Address_ID, [Address_ID]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Addresses-Select]    Script Date: [[20120714223930]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223930]]
-- Description:	select records from table [dbo].[Dealers_Addresses] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Addresses-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Addresses-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Addresses-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Address_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Dealers_Addresses]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Address_ID] = ISNULL(@Address_ID, [Address_ID]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Banks-Insert]    Script Date: [[20120714223930]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223930]]
-- Description:	Insert record into table [dbo].[Dealers_Banks]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Banks-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Banks-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Banks-Insert]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@AcountNumber varchar(100) =Null  , 
	@Bank_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Dealers_Banks](/*[ID], [Dealer_ID], [AcountNumber], [Bank_ID]*/)
	VALUES     (/*@ID, @Dealer_ID, @AcountNumber, @Bank_ID*/)

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Dealers_Banks]
    WHERE  ( [ID] =@ID )
	AND  ( [Dealer_ID] =@Dealer_ID )
	AND  ( [AcountNumber] =@AcountNumber )
	AND  ( [Bank_ID] =@Bank_ID )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Banks-update]    Script Date: [[20120714223930]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223930]]
-- Description:	Update record in table [dbo].[Dealers_Banks]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Banks-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Banks-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Banks-update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@AcountNumber varchar(100) =Null  , 
	@Bank_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Dealers_Banks] SET 
		/*[ID] =@ID, 
		[Dealer_ID] =@Dealer_ID, 
		[AcountNumber] =@AcountNumber, 
		[Bank_ID] =@Bank_ID*/
		/*WHERE ([ID] = @ID)*/
	/**/

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Dealers_Banks]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Banks-Insert-Update]    Script Date: [[20120714223930]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223930]]
-- Description:	Insert OR Update record into table [dbo].[Dealers_Banks]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Banks-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Banks-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Banks-Insert-Update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@AcountNumber varchar(100) =Null  , 
	@Bank_ID uniqueidentifier =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Dealers_Banks] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Dealers_Banks](/*[ID], [Dealer_ID], [AcountNumber], [Bank_ID]*/)
		VALUES     (/*@ID, @Dealer_ID, @AcountNumber, @Bank_ID*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Dealers_Banks] SET 
			/*[ID] =@ID, 
			[Dealer_ID] =@Dealer_ID, 
			[AcountNumber] =@AcountNumber, 
			[Bank_ID] =@Bank_ID*/
			/*WHERE ([ID] = @ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Dealers_Banks]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Banks-Delete]    Script Date: [[20120714223931]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223931]]
-- Description:	delete records from table [dbo].[Dealers_Banks] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Banks-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Banks-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Banks-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@AcountNumber varchar(100) =null  , 
	@Bank_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Dealers_Banks]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [AcountNumber] like ISNULL(@AcountNumber, [AcountNumber]) )
	AND ( [Bank_ID] = ISNULL(@Bank_ID, [Bank_ID]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Banks-Select]    Script Date: [[20120714223931]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223931]]
-- Description:	select records from table [dbo].[Dealers_Banks] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Banks-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Banks-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Banks-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@AcountNumber varchar(100) =null  , 
	@Bank_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Dealers_Banks]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [AcountNumber] like ISNULL(@AcountNumber, [AcountNumber]) )
	AND ( [Bank_ID] = ISNULL(@Bank_ID, [Bank_ID]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Products-Insert]    Script Date: [[20120714223931]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223931]]
-- Description:	Insert record into table [dbo].[Dealers_Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Products-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Products-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Products-Insert]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Dealers_Products](/*[ID], [Dealer_ID], [Product_ID], [MeasureUnit_ID]*/)
	VALUES     (/*@ID, @Dealer_ID, @Product_ID, @MeasureUnit_ID*/)

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Dealers_Products]
    WHERE  ( [ID] =@ID )
	AND  ( [Dealer_ID] =@Dealer_ID )
	AND  ( [Product_ID] =@Product_ID )
	AND  ( [MeasureUnit_ID] =@MeasureUnit_ID )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Products-update]    Script Date: [[20120714223931]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223931]]
-- Description:	Update record in table [dbo].[Dealers_Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Products-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Products-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Products-update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Dealers_Products] SET 
		/*[ID] =@ID, 
		[Dealer_ID] =@Dealer_ID, 
		[Product_ID] =@Product_ID, 
		[MeasureUnit_ID] =@MeasureUnit_ID*/
		/*WHERE ([ID] = @ID)*/
	/**/

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Dealers_Products]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Products-Insert-Update]    Script Date: [[20120714223931]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223931]]
-- Description:	Insert OR Update record into table [dbo].[Dealers_Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Products-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Products-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Products-Insert-Update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Dealers_Products] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Dealers_Products](/*[ID], [Dealer_ID], [Product_ID], [MeasureUnit_ID]*/)
		VALUES     (/*@ID, @Dealer_ID, @Product_ID, @MeasureUnit_ID*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Dealers_Products] SET 
			/*[ID] =@ID, 
			[Dealer_ID] =@Dealer_ID, 
			[Product_ID] =@Product_ID, 
			[MeasureUnit_ID] =@MeasureUnit_ID*/
			/*WHERE ([ID] = @ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Dealers_Products]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Products-Delete]    Script Date: [[20120714223931]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223931]]
-- Description:	delete records from table [dbo].[Dealers_Products] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Products-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Products-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Products-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@MeasureUnit_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Dealers_Products]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers_Products-Select]    Script Date: [[20120714223931]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223931]]
-- Description:	select records from table [dbo].[Dealers_Products] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers_Products-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers_Products-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers_Products-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@MeasureUnit_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Dealers_Products]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersContactPersons-Insert]    Script Date: [[20120714223932]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223932]]
-- Description:	Insert record into table [dbo].[DealersContactPersons]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersContactPersons-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersContactPersons-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersContactPersons-Insert]
	/*@Person_RowNumber int =Null OUTPUT , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Person_ID uniqueidentifier =Null  , 
	@Person_Code varchar(50) =Null  , 
	@Person_NameAr varchar(300) =Null  , 
	@Person_NameEn varchar(300) =Null  , 
	@Person_Notes varchar(max) =Null  , 
	@Person_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[DealersContactPersons](/*[Dealer_ID], [Person_ID], [Person_Code], [Person_NameAr], [Person_NameEn], [Person_Notes], [Person_Search]*/)
	VALUES     (/*@Dealer_ID, @Person_ID, @Person_Code, @Person_NameAr, @Person_NameEn, @Person_Notes, @Person_Search*/)

	/*SELECT @Person_RowNumber = [Person_RowNumber]
    FROM [dbo].[DealersContactPersons]
    WHERE  ( [Dealer_ID] =@Dealer_ID )
	AND  ( [Person_ID] =@Person_ID )
	AND  ( [Person_Code] =@Person_Code )
	AND  ( [Person_NameAr] =@Person_NameAr )
	AND  ( [Person_NameEn] =@Person_NameEn )
	AND  ( [Person_Notes] =@Person_Notes )
	AND  ( [Person_Search] =@Person_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersContactPersons-update]    Script Date: [[20120714223932]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223932]]
-- Description:	Update record in table [dbo].[DealersContactPersons]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersContactPersons-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersContactPersons-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersContactPersons-update]
	/*@Person_RowNumber int =Null OUTPUT , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Person_ID uniqueidentifier =Null  , 
	@Person_Code varchar(50) =Null  , 
	@Person_NameAr varchar(300) =Null  , 
	@Person_NameEn varchar(300) =Null  , 
	@Person_Notes varchar(max) =Null  , 
	@Person_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[DealersContactPersons] SET 
		/*[Dealer_ID] =@Dealer_ID, 
		[Person_ID] =@Person_ID, 
		[Person_Code] =@Person_Code, 
		[Person_NameAr] =@Person_NameAr, 
		[Person_NameEn] =@Person_NameEn, 
		[Person_Notes] =@Person_Notes, 
		[Person_Search] =@Person_Search*/
		/*WHERE ([Person_ID] = @Person_ID)*/
	/**/

	/*SELECT @Person_RowNumber = [Person_RowNumber]
    FROM [dbo].[DealersContactPersons]
	WHERE ([Person_ID] = @Person_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersContactPersons-Insert-Update]    Script Date: [[20120714223932]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223932]]
-- Description:	Insert OR Update record into table [dbo].[DealersContactPersons]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersContactPersons-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersContactPersons-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersContactPersons-Insert-Update]
	/*@Person_RowNumber int =Null OUTPUT , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Person_ID uniqueidentifier =Null  , 
	@Person_Code varchar(50) =Null  , 
	@Person_NameAr varchar(300) =Null  , 
	@Person_NameEn varchar(300) =Null  , 
	@Person_Notes varchar(max) =Null  , 
	@Person_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[DealersContactPersons] 
					/*WHERE ([Person_ID] = @Person_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[DealersContactPersons](/*[Dealer_ID], [Person_ID], [Person_Code], [Person_NameAr], [Person_NameEn], [Person_Notes], [Person_Search]*/)
		VALUES     (/*@Dealer_ID, @Person_ID, @Person_Code, @Person_NameAr, @Person_NameEn, @Person_Notes, @Person_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[DealersContactPersons] SET 
			/*[Dealer_ID] =@Dealer_ID, 
			[Person_ID] =@Person_ID, 
			[Person_Code] =@Person_Code, 
			[Person_NameAr] =@Person_NameAr, 
			[Person_NameEn] =@Person_NameEn, 
			[Person_Notes] =@Person_Notes, 
			[Person_Search] =@Person_Search*/
			/*WHERE ([Person_ID] = @Person_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Person_RowNumber = [Person_RowNumber]
    FROM [dbo].[DealersContactPersons]
	WHERE ([Person_ID] = @Person_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersContactPersons-Delete]    Script Date: [[20120714223932]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223932]]
-- Description:	delete records from table [dbo].[DealersContactPersons] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersContactPersons-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersContactPersons-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersContactPersons-Delete]
	/*@Person_RowNumber int =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Person_ID uniqueidentifier =null  , 
	@Person_Code varchar(50) =null  , 
	@Person_NameAr varchar(300) =null  , 
	@Person_NameEn varchar(300) =null  , 
	@Person_Notes varchar(max) =null  , 
	@Person_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[DealersContactPersons]
	WHERE /*( [Person_RowNumber] = ISNULL(@Person_RowNumber, [Person_RowNumber]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Person_ID] = ISNULL(@Person_ID, [Person_ID]) )
	AND ( [Person_Code] like ISNULL(@Person_Code, [Person_Code]) )
	AND ( [Person_NameAr] like ISNULL(@Person_NameAr, [Person_NameAr]) )
	AND ( [Person_NameEn] like ISNULL(@Person_NameEn, [Person_NameEn]) )
	AND ( [Person_Notes] like ISNULL(@Person_Notes, [Person_Notes]) )
	AND ( [Person_Search] like ISNULL(@Person_Search, [Person_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersContactPersons-Select]    Script Date: [[20120714223932]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223932]]
-- Description:	select records from table [dbo].[DealersContactPersons] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersContactPersons-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersContactPersons-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersContactPersons-Select]
	/*@Person_RowNumber int =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Person_ID uniqueidentifier =null  , 
	@Person_Code varchar(50) =null  , 
	@Person_NameAr varchar(300) =null  , 
	@Person_NameEn varchar(300) =null  , 
	@Person_Notes varchar(max) =null  , 
	@Person_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[DealersContactPersons]
	WHERE /*( [Person_RowNumber] = ISNULL(@Person_RowNumber, [Person_RowNumber]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Person_ID] = ISNULL(@Person_ID, [Person_ID]) )
	AND ( [Person_Code] like ISNULL(@Person_Code, [Person_Code]) )
	AND ( [Person_NameAr] like ISNULL(@Person_NameAr, [Person_NameAr]) )
	AND ( [Person_NameEn] like ISNULL(@Person_NameEn, [Person_NameEn]) )
	AND ( [Person_Notes] like ISNULL(@Person_Notes, [Person_Notes]) )
	AND ( [Person_Search] like ISNULL(@Person_Search, [Person_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersTypes-Insert]    Script Date: [[20120714223932]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223932]]
-- Description:	Insert record into table [dbo].[DealersTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersTypes-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersTypes-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersTypes-Insert]
	/*@DealerType_RowNumber int =Null OUTPUT , 
	@DealerType_ID uniqueidentifier =Null  , 
	@DealerType_ParentID uniqueidentifier =Null  , 
	@DealerTypeCode varchar(50) =Null  , 
	@DealerType_NameAr varchar(300) =Null  , 
	@DealerType_NameEn varchar(300) =Null  , 
	@DealerType_Notes varchar(max) =Null  , 
	@DealerType_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[DealersTypes](/*[DealerType_ID], [DealerType_ParentID], [DealerTypeCode], [DealerType_NameAr], [DealerType_NameEn], [DealerType_Notes], [DealerType_Search]*/)
	VALUES     (/*@DealerType_ID, @DealerType_ParentID, @DealerTypeCode, @DealerType_NameAr, @DealerType_NameEn, @DealerType_Notes, @DealerType_Search*/)

	/*SELECT @DealerType_RowNumber = [DealerType_RowNumber]
    FROM [dbo].[DealersTypes]
    WHERE  ( [DealerType_ID] =@DealerType_ID )
	AND  ( [DealerType_ParentID] =@DealerType_ParentID )
	AND  ( [DealerTypeCode] =@DealerTypeCode )
	AND  ( [DealerType_NameAr] =@DealerType_NameAr )
	AND  ( [DealerType_NameEn] =@DealerType_NameEn )
	AND  ( [DealerType_Notes] =@DealerType_Notes )
	AND  ( [DealerType_Search] =@DealerType_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersTypes-update]    Script Date: [[20120714223932]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223932]]
-- Description:	Update record in table [dbo].[DealersTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersTypes-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersTypes-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersTypes-update]
	/*@DealerType_RowNumber int =Null OUTPUT , 
	@DealerType_ID uniqueidentifier =Null  , 
	@DealerType_ParentID uniqueidentifier =Null  , 
	@DealerTypeCode varchar(50) =Null  , 
	@DealerType_NameAr varchar(300) =Null  , 
	@DealerType_NameEn varchar(300) =Null  , 
	@DealerType_Notes varchar(max) =Null  , 
	@DealerType_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[DealersTypes] SET 
		/*[DealerType_ID] =@DealerType_ID, 
		[DealerType_ParentID] =@DealerType_ParentID, 
		[DealerTypeCode] =@DealerTypeCode, 
		[DealerType_NameAr] =@DealerType_NameAr, 
		[DealerType_NameEn] =@DealerType_NameEn, 
		[DealerType_Notes] =@DealerType_Notes, 
		[DealerType_Search] =@DealerType_Search*/
		/*WHERE ([DealerType_ID] = @DealerType_ID)*/
	/**/

	/*SELECT @DealerType_RowNumber = [DealerType_RowNumber]
    FROM [dbo].[DealersTypes]
	WHERE ([DealerType_ID] = @DealerType_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersTypes-Insert-Update]    Script Date: [[20120714223932]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223932]]
-- Description:	Insert OR Update record into table [dbo].[DealersTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersTypes-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersTypes-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersTypes-Insert-Update]
	/*@DealerType_RowNumber int =Null OUTPUT , 
	@DealerType_ID uniqueidentifier =Null  , 
	@DealerType_ParentID uniqueidentifier =Null  , 
	@DealerTypeCode varchar(50) =Null  , 
	@DealerType_NameAr varchar(300) =Null  , 
	@DealerType_NameEn varchar(300) =Null  , 
	@DealerType_Notes varchar(max) =Null  , 
	@DealerType_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[DealersTypes] 
					/*WHERE ([DealerType_ID] = @DealerType_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[DealersTypes](/*[DealerType_ID], [DealerType_ParentID], [DealerTypeCode], [DealerType_NameAr], [DealerType_NameEn], [DealerType_Notes], [DealerType_Search]*/)
		VALUES     (/*@DealerType_ID, @DealerType_ParentID, @DealerTypeCode, @DealerType_NameAr, @DealerType_NameEn, @DealerType_Notes, @DealerType_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[DealersTypes] SET 
			/*[DealerType_ID] =@DealerType_ID, 
			[DealerType_ParentID] =@DealerType_ParentID, 
			[DealerTypeCode] =@DealerTypeCode, 
			[DealerType_NameAr] =@DealerType_NameAr, 
			[DealerType_NameEn] =@DealerType_NameEn, 
			[DealerType_Notes] =@DealerType_Notes, 
			[DealerType_Search] =@DealerType_Search*/
			/*WHERE ([DealerType_ID] = @DealerType_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @DealerType_RowNumber = [DealerType_RowNumber]
    FROM [dbo].[DealersTypes]
	WHERE ([DealerType_ID] = @DealerType_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersTypes-Delete]    Script Date: [[20120714223932]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223932]]
-- Description:	delete records from table [dbo].[DealersTypes] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersTypes-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersTypes-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersTypes-Delete]
	/*@DealerType_RowNumber int =null  , 
	@DealerType_ID uniqueidentifier =null  , 
	@DealerType_ParentID uniqueidentifier =null  , 
	@DealerTypeCode varchar(50) =null  , 
	@DealerType_NameAr varchar(300) =null  , 
	@DealerType_NameEn varchar(300) =null  , 
	@DealerType_Notes varchar(max) =null  , 
	@DealerType_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[DealersTypes]
	WHERE /*( [DealerType_RowNumber] = ISNULL(@DealerType_RowNumber, [DealerType_RowNumber]) )
	AND ( [DealerType_ID] = ISNULL(@DealerType_ID, [DealerType_ID]) )
	AND ( [DealerType_ParentID] = ISNULL(@DealerType_ParentID, [DealerType_ParentID]) )
	AND ( [DealerTypeCode] like ISNULL(@DealerTypeCode, [DealerTypeCode]) )
	AND ( [DealerType_NameAr] like ISNULL(@DealerType_NameAr, [DealerType_NameAr]) )
	AND ( [DealerType_NameEn] like ISNULL(@DealerType_NameEn, [DealerType_NameEn]) )
	AND ( [DealerType_Notes] like ISNULL(@DealerType_Notes, [DealerType_Notes]) )
	AND ( [DealerType_Search] like ISNULL(@DealerType_Search, [DealerType_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersTypes-Select]    Script Date: [[20120714223933]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223933]]
-- Description:	select records from table [dbo].[DealersTypes] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersTypes-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersTypes-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersTypes-Select]
	/*@DealerType_RowNumber int =null  , 
	@DealerType_ID uniqueidentifier =null  , 
	@DealerType_ParentID uniqueidentifier =null  , 
	@DealerTypeCode varchar(50) =null  , 
	@DealerType_NameAr varchar(300) =null  , 
	@DealerType_NameEn varchar(300) =null  , 
	@DealerType_Notes varchar(max) =null  , 
	@DealerType_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[DealersTypes]
	WHERE /*( [DealerType_RowNumber] = ISNULL(@DealerType_RowNumber, [DealerType_RowNumber]) )
	AND ( [DealerType_ID] = ISNULL(@DealerType_ID, [DealerType_ID]) )
	AND ( [DealerType_ParentID] = ISNULL(@DealerType_ParentID, [DealerType_ParentID]) )
	AND ( [DealerTypeCode] like ISNULL(@DealerTypeCode, [DealerTypeCode]) )
	AND ( [DealerType_NameAr] like ISNULL(@DealerType_NameAr, [DealerType_NameAr]) )
	AND ( [DealerType_NameEn] like ISNULL(@DealerType_NameEn, [DealerType_NameEn]) )
	AND ( [DealerType_Notes] like ISNULL(@DealerType_Notes, [DealerType_Notes]) )
	AND ( [DealerType_Search] like ISNULL(@DealerType_Search, [DealerType_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Groups-Insert]    Script Date: [[20120714223933]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223933]]
-- Description:	Insert record into table [dbo].[Groups]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups-Insert]
	/*@Group_RowNumber int =Null OUTPUT , 
	@Group_ID uniqueidentifier =Null  , 
	@Group_NameAr varchar(200) =Null  , 
	@Group_NameEn varchar(200) =Null  , 
	@Group_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Groups](/*[Group_ID], [Group_NameAr], [Group_NameEn], [Group_Search]*/)
	VALUES     (/*@Group_ID, @Group_NameAr, @Group_NameEn, @Group_Search*/)

	/*SELECT @Group_RowNumber = [Group_RowNumber]
    FROM [dbo].[Groups]
    WHERE  ( [Group_ID] =@Group_ID )
	AND  ( [Group_NameAr] =@Group_NameAr )
	AND  ( [Group_NameEn] =@Group_NameEn )
	AND  ( [Group_Search] =@Group_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Groups-update]    Script Date: [[20120714223933]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223933]]
-- Description:	Update record in table [dbo].[Groups]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups-update]
	/*@Group_RowNumber int =Null OUTPUT , 
	@Group_ID uniqueidentifier =Null  , 
	@Group_NameAr varchar(200) =Null  , 
	@Group_NameEn varchar(200) =Null  , 
	@Group_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Groups] SET 
		/*[Group_ID] =@Group_ID, 
		[Group_NameAr] =@Group_NameAr, 
		[Group_NameEn] =@Group_NameEn, 
		[Group_Search] =@Group_Search*/
		/*WHERE ([Group_ID] = @Group_ID)*/
	/**/

	/*SELECT @Group_RowNumber = [Group_RowNumber]
    FROM [dbo].[Groups]
	WHERE ([Group_ID] = @Group_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Groups-Insert-Update]    Script Date: [[20120714223933]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223933]]
-- Description:	Insert OR Update record into table [dbo].[Groups]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups-Insert-Update]
	/*@Group_RowNumber int =Null OUTPUT , 
	@Group_ID uniqueidentifier =Null  , 
	@Group_NameAr varchar(200) =Null  , 
	@Group_NameEn varchar(200) =Null  , 
	@Group_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Groups] 
					/*WHERE ([Group_ID] = @Group_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Groups](/*[Group_ID], [Group_NameAr], [Group_NameEn], [Group_Search]*/)
		VALUES     (/*@Group_ID, @Group_NameAr, @Group_NameEn, @Group_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Groups] SET 
			/*[Group_ID] =@Group_ID, 
			[Group_NameAr] =@Group_NameAr, 
			[Group_NameEn] =@Group_NameEn, 
			[Group_Search] =@Group_Search*/
			/*WHERE ([Group_ID] = @Group_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Group_RowNumber = [Group_RowNumber]
    FROM [dbo].[Groups]
	WHERE ([Group_ID] = @Group_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Groups-Delete]    Script Date: [[20120714223933]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223933]]
-- Description:	delete records from table [dbo].[Groups] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups-Delete]
	/*@Group_RowNumber int =null  , 
	@Group_ID uniqueidentifier =null  , 
	@Group_NameAr varchar(200) =null  , 
	@Group_NameEn varchar(200) =null  , 
	@Group_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Groups]
	WHERE /*( [Group_RowNumber] = ISNULL(@Group_RowNumber, [Group_RowNumber]) )
	AND ( [Group_ID] = ISNULL(@Group_ID, [Group_ID]) )
	AND ( [Group_NameAr] like ISNULL(@Group_NameAr, [Group_NameAr]) )
	AND ( [Group_NameEn] like ISNULL(@Group_NameEn, [Group_NameEn]) )
	AND ( [Group_Search] like ISNULL(@Group_Search, [Group_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Groups-Select]    Script Date: [[20120714223933]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223933]]
-- Description:	select records from table [dbo].[Groups] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups-Select]
	/*@Group_RowNumber int =null  , 
	@Group_ID uniqueidentifier =null  , 
	@Group_NameAr varchar(200) =null  , 
	@Group_NameEn varchar(200) =null  , 
	@Group_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Groups]
	WHERE /*( [Group_RowNumber] = ISNULL(@Group_RowNumber, [Group_RowNumber]) )
	AND ( [Group_ID] = ISNULL(@Group_ID, [Group_ID]) )
	AND ( [Group_NameAr] like ISNULL(@Group_NameAr, [Group_NameAr]) )
	AND ( [Group_NameEn] like ISNULL(@Group_NameEn, [Group_NameEn]) )
	AND ( [Group_Search] like ISNULL(@Group_Search, [Group_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Groups_Permissions-Insert]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	Insert record into table [dbo].[Groups_Permissions]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups_Permissions-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups_Permissions-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups_Permissions-Insert]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Group_ID uniqueidentifier =Null  , 
	@Permission_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Groups_Permissions](/*[ID], [Group_ID], [Permission_ID]*/)
	VALUES     (/*@ID, @Group_ID, @Permission_ID*/)

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Groups_Permissions]
    WHERE  ( [ID] =@ID )
	AND  ( [Group_ID] =@Group_ID )
	AND  ( [Permission_ID] =@Permission_ID )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Groups_Permissions-update]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	Update record in table [dbo].[Groups_Permissions]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups_Permissions-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups_Permissions-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups_Permissions-update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Group_ID uniqueidentifier =Null  , 
	@Permission_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Groups_Permissions] SET 
		/*[ID] =@ID, 
		[Group_ID] =@Group_ID, 
		[Permission_ID] =@Permission_ID*/
		/*WHERE ([ID] = @ID)*/
	/**/

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Groups_Permissions]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Groups_Permissions-Insert-Update]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	Insert OR Update record into table [dbo].[Groups_Permissions]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups_Permissions-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups_Permissions-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups_Permissions-Insert-Update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Group_ID uniqueidentifier =Null  , 
	@Permission_ID uniqueidentifier =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Groups_Permissions] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Groups_Permissions](/*[ID], [Group_ID], [Permission_ID]*/)
		VALUES     (/*@ID, @Group_ID, @Permission_ID*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Groups_Permissions] SET 
			/*[ID] =@ID, 
			[Group_ID] =@Group_ID, 
			[Permission_ID] =@Permission_ID*/
			/*WHERE ([ID] = @ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Groups_Permissions]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Groups_Permissions-Delete]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	delete records from table [dbo].[Groups_Permissions] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups_Permissions-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups_Permissions-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups_Permissions-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Group_ID uniqueidentifier =null  , 
	@Permission_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Groups_Permissions]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Group_ID] = ISNULL(@Group_ID, [Group_ID]) )
	AND ( [Permission_ID] = ISNULL(@Permission_ID, [Permission_ID]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Groups_Permissions-Select]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	select records from table [dbo].[Groups_Permissions] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups_Permissions-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups_Permissions-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups_Permissions-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Group_ID uniqueidentifier =null  , 
	@Permission_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Groups_Permissions]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Group_ID] = ISNULL(@Group_ID, [Group_ID]) )
	AND ( [Permission_ID] = ISNULL(@Permission_ID, [Permission_ID]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[MeasureUnits-Insert]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	Insert record into table [dbo].[MeasureUnits]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[MeasureUnits-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[MeasureUnits-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[MeasureUnits-Insert]
	/*@MeasureUnit_RowNumber int =Null OUTPUT , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@MeasureUnit_Code varchar(50) =Null  , 
	@MeasureUnit_NameAr varchar(300) =Null  , 
	@MeasureUnit_NameEn varchar(300) =Null  , 
	@MeasureUnit_Notes varchar(max) =Null  , 
	@MeasureUnit_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[MeasureUnits](/*[MeasureUnit_ID], [MeasureUnit_Code], [MeasureUnit_NameAr], [MeasureUnit_NameEn], [MeasureUnit_Notes], [MeasureUnit_Search]*/)
	VALUES     (/*@MeasureUnit_ID, @MeasureUnit_Code, @MeasureUnit_NameAr, @MeasureUnit_NameEn, @MeasureUnit_Notes, @MeasureUnit_Search*/)

	/*SELECT @MeasureUnit_RowNumber = [MeasureUnit_RowNumber]
    FROM [dbo].[MeasureUnits]
    WHERE  ( [MeasureUnit_ID] =@MeasureUnit_ID )
	AND  ( [MeasureUnit_Code] =@MeasureUnit_Code )
	AND  ( [MeasureUnit_NameAr] =@MeasureUnit_NameAr )
	AND  ( [MeasureUnit_NameEn] =@MeasureUnit_NameEn )
	AND  ( [MeasureUnit_Notes] =@MeasureUnit_Notes )
	AND  ( [MeasureUnit_Search] =@MeasureUnit_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[MeasureUnits-update]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	Update record in table [dbo].[MeasureUnits]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[MeasureUnits-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[MeasureUnits-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[MeasureUnits-update]
	/*@MeasureUnit_RowNumber int =Null OUTPUT , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@MeasureUnit_Code varchar(50) =Null  , 
	@MeasureUnit_NameAr varchar(300) =Null  , 
	@MeasureUnit_NameEn varchar(300) =Null  , 
	@MeasureUnit_Notes varchar(max) =Null  , 
	@MeasureUnit_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[MeasureUnits] SET 
		/*[MeasureUnit_ID] =@MeasureUnit_ID, 
		[MeasureUnit_Code] =@MeasureUnit_Code, 
		[MeasureUnit_NameAr] =@MeasureUnit_NameAr, 
		[MeasureUnit_NameEn] =@MeasureUnit_NameEn, 
		[MeasureUnit_Notes] =@MeasureUnit_Notes, 
		[MeasureUnit_Search] =@MeasureUnit_Search*/
		/*WHERE ([MeasureUnit_ID] = @MeasureUnit_ID)*/
	/**/

	/*SELECT @MeasureUnit_RowNumber = [MeasureUnit_RowNumber]
    FROM [dbo].[MeasureUnits]
	WHERE ([MeasureUnit_ID] = @MeasureUnit_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[MeasureUnits-Insert-Update]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	Insert OR Update record into table [dbo].[MeasureUnits]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[MeasureUnits-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[MeasureUnits-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[MeasureUnits-Insert-Update]
	/*@MeasureUnit_RowNumber int =Null OUTPUT , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@MeasureUnit_Code varchar(50) =Null  , 
	@MeasureUnit_NameAr varchar(300) =Null  , 
	@MeasureUnit_NameEn varchar(300) =Null  , 
	@MeasureUnit_Notes varchar(max) =Null  , 
	@MeasureUnit_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[MeasureUnits] 
					/*WHERE ([MeasureUnit_ID] = @MeasureUnit_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[MeasureUnits](/*[MeasureUnit_ID], [MeasureUnit_Code], [MeasureUnit_NameAr], [MeasureUnit_NameEn], [MeasureUnit_Notes], [MeasureUnit_Search]*/)
		VALUES     (/*@MeasureUnit_ID, @MeasureUnit_Code, @MeasureUnit_NameAr, @MeasureUnit_NameEn, @MeasureUnit_Notes, @MeasureUnit_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[MeasureUnits] SET 
			/*[MeasureUnit_ID] =@MeasureUnit_ID, 
			[MeasureUnit_Code] =@MeasureUnit_Code, 
			[MeasureUnit_NameAr] =@MeasureUnit_NameAr, 
			[MeasureUnit_NameEn] =@MeasureUnit_NameEn, 
			[MeasureUnit_Notes] =@MeasureUnit_Notes, 
			[MeasureUnit_Search] =@MeasureUnit_Search*/
			/*WHERE ([MeasureUnit_ID] = @MeasureUnit_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @MeasureUnit_RowNumber = [MeasureUnit_RowNumber]
    FROM [dbo].[MeasureUnits]
	WHERE ([MeasureUnit_ID] = @MeasureUnit_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[MeasureUnits-Delete]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	delete records from table [dbo].[MeasureUnits] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[MeasureUnits-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[MeasureUnits-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[MeasureUnits-Delete]
	/*@MeasureUnit_RowNumber int =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@MeasureUnit_Code varchar(50) =null  , 
	@MeasureUnit_NameAr varchar(300) =null  , 
	@MeasureUnit_NameEn varchar(300) =null  , 
	@MeasureUnit_Notes varchar(max) =null  , 
	@MeasureUnit_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[MeasureUnits]
	WHERE /*( [MeasureUnit_RowNumber] = ISNULL(@MeasureUnit_RowNumber, [MeasureUnit_RowNumber]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [MeasureUnit_Code] like ISNULL(@MeasureUnit_Code, [MeasureUnit_Code]) )
	AND ( [MeasureUnit_NameAr] like ISNULL(@MeasureUnit_NameAr, [MeasureUnit_NameAr]) )
	AND ( [MeasureUnit_NameEn] like ISNULL(@MeasureUnit_NameEn, [MeasureUnit_NameEn]) )
	AND ( [MeasureUnit_Notes] like ISNULL(@MeasureUnit_Notes, [MeasureUnit_Notes]) )
	AND ( [MeasureUnit_Search] like ISNULL(@MeasureUnit_Search, [MeasureUnit_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[MeasureUnits-Select]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	select records from table [dbo].[MeasureUnits] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[MeasureUnits-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[MeasureUnits-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[MeasureUnits-Select]
	/*@MeasureUnit_RowNumber int =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@MeasureUnit_Code varchar(50) =null  , 
	@MeasureUnit_NameAr varchar(300) =null  , 
	@MeasureUnit_NameEn varchar(300) =null  , 
	@MeasureUnit_Notes varchar(max) =null  , 
	@MeasureUnit_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[MeasureUnits]
	WHERE /*( [MeasureUnit_RowNumber] = ISNULL(@MeasureUnit_RowNumber, [MeasureUnit_RowNumber]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [MeasureUnit_Code] like ISNULL(@MeasureUnit_Code, [MeasureUnit_Code]) )
	AND ( [MeasureUnit_NameAr] like ISNULL(@MeasureUnit_NameAr, [MeasureUnit_NameAr]) )
	AND ( [MeasureUnit_NameEn] like ISNULL(@MeasureUnit_NameEn, [MeasureUnit_NameEn]) )
	AND ( [MeasureUnit_Notes] like ISNULL(@MeasureUnit_Notes, [MeasureUnit_Notes]) )
	AND ( [MeasureUnit_Search] like ISNULL(@MeasureUnit_Search, [MeasureUnit_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Offers-Insert]    Script Date: [[20120714223935]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223935]]
-- Description:	Insert record into table [dbo].[Offers]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Offers-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Offers-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Offers-Insert]
	/*@Offer_RowNumber int =Null OUTPUT , 
	@Offer_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Quantity float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@TotalPrice float =Null  , 
	@IsForeEver nchar =0  , 
	@FromDate datetime =Null  , 
	@ToDate datetime =Null  , 
	@Offer_Notes varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Offers](/*[Offer_ID], [Product_ID], [Quantity], [MeasureUnit_ID], [TotalPrice], [IsForeEver], [FromDate], [ToDate], [Offer_Notes]*/)
	VALUES     (/*@Offer_ID, @Product_ID, @Quantity, @MeasureUnit_ID, @TotalPrice, @IsForeEver, @FromDate, @ToDate, @Offer_Notes*/)

	/*SELECT @Offer_RowNumber = [Offer_RowNumber]
    FROM [dbo].[Offers]
    WHERE  ( [Offer_ID] =@Offer_ID )
	AND  ( [Product_ID] =@Product_ID )
	AND  ( [Quantity] =@Quantity )
	AND  ( [MeasureUnit_ID] =@MeasureUnit_ID )
	AND  ( [TotalPrice] =@TotalPrice )
	AND  ( [IsForeEver] =@IsForeEver )
	AND  ( [FromDate] =@FromDate )
	AND  ( [ToDate] =@ToDate )
	AND  ( [Offer_Notes] =@Offer_Notes )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Offers-update]    Script Date: [[20120714223935]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223935]]
-- Description:	Update record in table [dbo].[Offers]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Offers-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Offers-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Offers-update]
	/*@Offer_RowNumber int =Null OUTPUT , 
	@Offer_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Quantity float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@TotalPrice float =Null  , 
	@IsForeEver nchar =0  , 
	@FromDate datetime =Null  , 
	@ToDate datetime =Null  , 
	@Offer_Notes varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Offers] SET 
		/*[Offer_ID] =@Offer_ID, 
		[Product_ID] =@Product_ID, 
		[Quantity] =@Quantity, 
		[MeasureUnit_ID] =@MeasureUnit_ID, 
		[TotalPrice] =@TotalPrice, 
		[IsForeEver] =@IsForeEver, 
		[FromDate] =@FromDate, 
		[ToDate] =@ToDate, 
		[Offer_Notes] =@Offer_Notes*/
		/*WHERE ([Offer_ID] = @Offer_ID)*/
	/**/

	/*SELECT @Offer_RowNumber = [Offer_RowNumber]
    FROM [dbo].[Offers]
	WHERE ([Offer_ID] = @Offer_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Offers-Insert-Update]    Script Date: [[20120714223935]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223935]]
-- Description:	Insert OR Update record into table [dbo].[Offers]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Offers-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Offers-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Offers-Insert-Update]
	/*@Offer_RowNumber int =Null OUTPUT , 
	@Offer_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Quantity float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@TotalPrice float =Null  , 
	@IsForeEver nchar =0  , 
	@FromDate datetime =Null  , 
	@ToDate datetime =Null  , 
	@Offer_Notes varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Offers] 
					/*WHERE ([Offer_ID] = @Offer_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Offers](/*[Offer_ID], [Product_ID], [Quantity], [MeasureUnit_ID], [TotalPrice], [IsForeEver], [FromDate], [ToDate], [Offer_Notes]*/)
		VALUES     (/*@Offer_ID, @Product_ID, @Quantity, @MeasureUnit_ID, @TotalPrice, @IsForeEver, @FromDate, @ToDate, @Offer_Notes*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Offers] SET 
			/*[Offer_ID] =@Offer_ID, 
			[Product_ID] =@Product_ID, 
			[Quantity] =@Quantity, 
			[MeasureUnit_ID] =@MeasureUnit_ID, 
			[TotalPrice] =@TotalPrice, 
			[IsForeEver] =@IsForeEver, 
			[FromDate] =@FromDate, 
			[ToDate] =@ToDate, 
			[Offer_Notes] =@Offer_Notes*/
			/*WHERE ([Offer_ID] = @Offer_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Offer_RowNumber = [Offer_RowNumber]
    FROM [dbo].[Offers]
	WHERE ([Offer_ID] = @Offer_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Offers-Delete]    Script Date: [[20120714223935]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223935]]
-- Description:	delete records from table [dbo].[Offers] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Offers-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Offers-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Offers-Delete]
	/*@Offer_RowNumber int =null  , 
	@Offer_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Quantity float =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@TotalPrice float =null  , 
	@IsForeEver nchar =null  , 
	@FromDate datetime =null  , 
	@ToDate datetime =null  , 
	@Offer_Notes varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Offers]
	WHERE /*( [Offer_RowNumber] = ISNULL(@Offer_RowNumber, [Offer_RowNumber]) )
	AND ( [Offer_ID] = ISNULL(@Offer_ID, [Offer_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Quantity] = ISNULL(@Quantity, [Quantity]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [TotalPrice] = ISNULL(@TotalPrice, [TotalPrice]) )
	AND ( [IsForeEver] = ISNULL(@IsForeEver, [IsForeEver]) )
	AND ( [FromDate] = ISNULL(@FromDate, [FromDate]) )
	AND ( [ToDate] = ISNULL(@ToDate, [ToDate]) )
	AND ( [Offer_Notes] like ISNULL(@Offer_Notes, [Offer_Notes]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Offers-Select]    Script Date: [[20120714223935]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223935]]
-- Description:	select records from table [dbo].[Offers] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Offers-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Offers-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Offers-Select]
	/*@Offer_RowNumber int =null  , 
	@Offer_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Quantity float =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@TotalPrice float =null  , 
	@IsForeEver nchar =null  , 
	@FromDate datetime =null  , 
	@ToDate datetime =null  , 
	@Offer_Notes varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Offers]
	WHERE /*( [Offer_RowNumber] = ISNULL(@Offer_RowNumber, [Offer_RowNumber]) )
	AND ( [Offer_ID] = ISNULL(@Offer_ID, [Offer_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Quantity] = ISNULL(@Quantity, [Quantity]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [TotalPrice] = ISNULL(@TotalPrice, [TotalPrice]) )
	AND ( [IsForeEver] = ISNULL(@IsForeEver, [IsForeEver]) )
	AND ( [FromDate] = ISNULL(@FromDate, [FromDate]) )
	AND ( [ToDate] = ISNULL(@ToDate, [ToDate]) )
	AND ( [Offer_Notes] like ISNULL(@Offer_Notes, [Offer_Notes]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Permissions-Insert]    Script Date: [[20120714223936]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223936]]
-- Description:	Insert record into table [dbo].[Permissions]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Permissions-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Permissions-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Permissions-Insert]
	/*@Permission_RowNumber int =Null OUTPUT , 
	@Permission_ID uniqueidentifier =Null  , 
	@Permission_NameAr varchar(200) =Null  , 
	@Permission_NameEn varchar(200) =Null  , 
	@Permission_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Permissions](/*[Permission_ID], [Permission_NameAr], [Permission_NameEn], [Permission_Search]*/)
	VALUES     (/*@Permission_ID, @Permission_NameAr, @Permission_NameEn, @Permission_Search*/)

	/*SELECT @Permission_RowNumber = [Permission_RowNumber]
    FROM [dbo].[Permissions]
    WHERE  ( [Permission_ID] =@Permission_ID )
	AND  ( [Permission_NameAr] =@Permission_NameAr )
	AND  ( [Permission_NameEn] =@Permission_NameEn )
	AND  ( [Permission_Search] =@Permission_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Permissions-update]    Script Date: [[20120714223936]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223936]]
-- Description:	Update record in table [dbo].[Permissions]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Permissions-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Permissions-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Permissions-update]
	/*@Permission_RowNumber int =Null OUTPUT , 
	@Permission_ID uniqueidentifier =Null  , 
	@Permission_NameAr varchar(200) =Null  , 
	@Permission_NameEn varchar(200) =Null  , 
	@Permission_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Permissions] SET 
		/*[Permission_ID] =@Permission_ID, 
		[Permission_NameAr] =@Permission_NameAr, 
		[Permission_NameEn] =@Permission_NameEn, 
		[Permission_Search] =@Permission_Search*/
		/*WHERE ([Permission_ID] = @Permission_ID)*/
	/**/

	/*SELECT @Permission_RowNumber = [Permission_RowNumber]
    FROM [dbo].[Permissions]
	WHERE ([Permission_ID] = @Permission_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Permissions-Insert-Update]    Script Date: [[20120714223936]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223936]]
-- Description:	Insert OR Update record into table [dbo].[Permissions]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Permissions-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Permissions-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Permissions-Insert-Update]
	/*@Permission_RowNumber int =Null OUTPUT , 
	@Permission_ID uniqueidentifier =Null  , 
	@Permission_NameAr varchar(200) =Null  , 
	@Permission_NameEn varchar(200) =Null  , 
	@Permission_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Permissions] 
					/*WHERE ([Permission_ID] = @Permission_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Permissions](/*[Permission_ID], [Permission_NameAr], [Permission_NameEn], [Permission_Search]*/)
		VALUES     (/*@Permission_ID, @Permission_NameAr, @Permission_NameEn, @Permission_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Permissions] SET 
			/*[Permission_ID] =@Permission_ID, 
			[Permission_NameAr] =@Permission_NameAr, 
			[Permission_NameEn] =@Permission_NameEn, 
			[Permission_Search] =@Permission_Search*/
			/*WHERE ([Permission_ID] = @Permission_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Permission_RowNumber = [Permission_RowNumber]
    FROM [dbo].[Permissions]
	WHERE ([Permission_ID] = @Permission_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Permissions-Delete]    Script Date: [[20120714223936]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223936]]
-- Description:	delete records from table [dbo].[Permissions] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Permissions-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Permissions-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Permissions-Delete]
	/*@Permission_RowNumber int =null  , 
	@Permission_ID uniqueidentifier =null  , 
	@Permission_NameAr varchar(200) =null  , 
	@Permission_NameEn varchar(200) =null  , 
	@Permission_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Permissions]
	WHERE /*( [Permission_RowNumber] = ISNULL(@Permission_RowNumber, [Permission_RowNumber]) )
	AND ( [Permission_ID] = ISNULL(@Permission_ID, [Permission_ID]) )
	AND ( [Permission_NameAr] like ISNULL(@Permission_NameAr, [Permission_NameAr]) )
	AND ( [Permission_NameEn] like ISNULL(@Permission_NameEn, [Permission_NameEn]) )
	AND ( [Permission_Search] like ISNULL(@Permission_Search, [Permission_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Permissions-Select]    Script Date: [[20120714223936]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223936]]
-- Description:	select records from table [dbo].[Permissions] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Permissions-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Permissions-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Permissions-Select]
	/*@Permission_RowNumber int =null  , 
	@Permission_ID uniqueidentifier =null  , 
	@Permission_NameAr varchar(200) =null  , 
	@Permission_NameEn varchar(200) =null  , 
	@Permission_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Permissions]
	WHERE /*( [Permission_RowNumber] = ISNULL(@Permission_RowNumber, [Permission_RowNumber]) )
	AND ( [Permission_ID] = ISNULL(@Permission_ID, [Permission_ID]) )
	AND ( [Permission_NameAr] like ISNULL(@Permission_NameAr, [Permission_NameAr]) )
	AND ( [Permission_NameEn] like ISNULL(@Permission_NameEn, [Permission_NameEn]) )
	AND ( [Permission_Search] like ISNULL(@Permission_Search, [Permission_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ProductClassifications-Insert]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	Insert record into table [dbo].[ProductClassifications]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ProductClassifications-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ProductClassifications-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ProductClassifications-Insert]
	/*@ProductClassification_RowNumber int =Null OUTPUT , 
	@ProductClassification_ID uniqueidentifier =Null  , 
	@ProductClassification_ParentID uniqueidentifier =Null  , 
	@ProductClassification_Code varchar(50) =Null  , 
	@ProductClassification_NameAr varchar(300) =Null  , 
	@ProductClassification_NameEn varchar(300) =Null  , 
	@ProductClassification_Notes varchar(max) =Null  , 
	@ProductClassification_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[ProductClassifications](/*[ProductClassification_ID], [ProductClassification_ParentID], [ProductClassification_Code], [ProductClassification_NameAr], [ProductClassification_NameEn], [ProductClassification_Notes], [ProductClassification_Search]*/)
	VALUES     (/*@ProductClassification_ID, @ProductClassification_ParentID, @ProductClassification_Code, @ProductClassification_NameAr, @ProductClassification_NameEn, @ProductClassification_Notes, @ProductClassification_Search*/)

	/*SELECT @ProductClassification_RowNumber = [ProductClassification_RowNumber]
    FROM [dbo].[ProductClassifications]
    WHERE  ( [ProductClassification_ID] =@ProductClassification_ID )
	AND  ( [ProductClassification_ParentID] =@ProductClassification_ParentID )
	AND  ( [ProductClassification_Code] =@ProductClassification_Code )
	AND  ( [ProductClassification_NameAr] =@ProductClassification_NameAr )
	AND  ( [ProductClassification_NameEn] =@ProductClassification_NameEn )
	AND  ( [ProductClassification_Notes] =@ProductClassification_Notes )
	AND  ( [ProductClassification_Search] =@ProductClassification_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ProductClassifications-update]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	Update record in table [dbo].[ProductClassifications]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ProductClassifications-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ProductClassifications-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ProductClassifications-update]
	/*@ProductClassification_RowNumber int =Null OUTPUT , 
	@ProductClassification_ID uniqueidentifier =Null  , 
	@ProductClassification_ParentID uniqueidentifier =Null  , 
	@ProductClassification_Code varchar(50) =Null  , 
	@ProductClassification_NameAr varchar(300) =Null  , 
	@ProductClassification_NameEn varchar(300) =Null  , 
	@ProductClassification_Notes varchar(max) =Null  , 
	@ProductClassification_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[ProductClassifications] SET 
		/*[ProductClassification_ID] =@ProductClassification_ID, 
		[ProductClassification_ParentID] =@ProductClassification_ParentID, 
		[ProductClassification_Code] =@ProductClassification_Code, 
		[ProductClassification_NameAr] =@ProductClassification_NameAr, 
		[ProductClassification_NameEn] =@ProductClassification_NameEn, 
		[ProductClassification_Notes] =@ProductClassification_Notes, 
		[ProductClassification_Search] =@ProductClassification_Search*/
		/*WHERE ([ProductClassification_ID] = @ProductClassification_ID)*/
	/**/

	/*SELECT @ProductClassification_RowNumber = [ProductClassification_RowNumber]
    FROM [dbo].[ProductClassifications]
	WHERE ([ProductClassification_ID] = @ProductClassification_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ProductClassifications-Insert-Update]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	Insert OR Update record into table [dbo].[ProductClassifications]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ProductClassifications-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ProductClassifications-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ProductClassifications-Insert-Update]
	/*@ProductClassification_RowNumber int =Null OUTPUT , 
	@ProductClassification_ID uniqueidentifier =Null  , 
	@ProductClassification_ParentID uniqueidentifier =Null  , 
	@ProductClassification_Code varchar(50) =Null  , 
	@ProductClassification_NameAr varchar(300) =Null  , 
	@ProductClassification_NameEn varchar(300) =Null  , 
	@ProductClassification_Notes varchar(max) =Null  , 
	@ProductClassification_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[ProductClassifications] 
					/*WHERE ([ProductClassification_ID] = @ProductClassification_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[ProductClassifications](/*[ProductClassification_ID], [ProductClassification_ParentID], [ProductClassification_Code], [ProductClassification_NameAr], [ProductClassification_NameEn], [ProductClassification_Notes], [ProductClassification_Search]*/)
		VALUES     (/*@ProductClassification_ID, @ProductClassification_ParentID, @ProductClassification_Code, @ProductClassification_NameAr, @ProductClassification_NameEn, @ProductClassification_Notes, @ProductClassification_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[ProductClassifications] SET 
			/*[ProductClassification_ID] =@ProductClassification_ID, 
			[ProductClassification_ParentID] =@ProductClassification_ParentID, 
			[ProductClassification_Code] =@ProductClassification_Code, 
			[ProductClassification_NameAr] =@ProductClassification_NameAr, 
			[ProductClassification_NameEn] =@ProductClassification_NameEn, 
			[ProductClassification_Notes] =@ProductClassification_Notes, 
			[ProductClassification_Search] =@ProductClassification_Search*/
			/*WHERE ([ProductClassification_ID] = @ProductClassification_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @ProductClassification_RowNumber = [ProductClassification_RowNumber]
    FROM [dbo].[ProductClassifications]
	WHERE ([ProductClassification_ID] = @ProductClassification_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ProductClassifications-Delete]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	delete records from table [dbo].[ProductClassifications] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ProductClassifications-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ProductClassifications-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ProductClassifications-Delete]
	/*@ProductClassification_RowNumber int =null  , 
	@ProductClassification_ID uniqueidentifier =null  , 
	@ProductClassification_ParentID uniqueidentifier =null  , 
	@ProductClassification_Code varchar(50) =null  , 
	@ProductClassification_NameAr varchar(300) =null  , 
	@ProductClassification_NameEn varchar(300) =null  , 
	@ProductClassification_Notes varchar(max) =null  , 
	@ProductClassification_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[ProductClassifications]
	WHERE /*( [ProductClassification_RowNumber] = ISNULL(@ProductClassification_RowNumber, [ProductClassification_RowNumber]) )
	AND ( [ProductClassification_ID] = ISNULL(@ProductClassification_ID, [ProductClassification_ID]) )
	AND ( [ProductClassification_ParentID] = ISNULL(@ProductClassification_ParentID, [ProductClassification_ParentID]) )
	AND ( [ProductClassification_Code] like ISNULL(@ProductClassification_Code, [ProductClassification_Code]) )
	AND ( [ProductClassification_NameAr] like ISNULL(@ProductClassification_NameAr, [ProductClassification_NameAr]) )
	AND ( [ProductClassification_NameEn] like ISNULL(@ProductClassification_NameEn, [ProductClassification_NameEn]) )
	AND ( [ProductClassification_Notes] like ISNULL(@ProductClassification_Notes, [ProductClassification_Notes]) )
	AND ( [ProductClassification_Search] like ISNULL(@ProductClassification_Search, [ProductClassification_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ProductClassifications-Select]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	select records from table [dbo].[ProductClassifications] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ProductClassifications-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ProductClassifications-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ProductClassifications-Select]
	/*@ProductClassification_RowNumber int =null  , 
	@ProductClassification_ID uniqueidentifier =null  , 
	@ProductClassification_ParentID uniqueidentifier =null  , 
	@ProductClassification_Code varchar(50) =null  , 
	@ProductClassification_NameAr varchar(300) =null  , 
	@ProductClassification_NameEn varchar(300) =null  , 
	@ProductClassification_Notes varchar(max) =null  , 
	@ProductClassification_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[ProductClassifications]
	WHERE /*( [ProductClassification_RowNumber] = ISNULL(@ProductClassification_RowNumber, [ProductClassification_RowNumber]) )
	AND ( [ProductClassification_ID] = ISNULL(@ProductClassification_ID, [ProductClassification_ID]) )
	AND ( [ProductClassification_ParentID] = ISNULL(@ProductClassification_ParentID, [ProductClassification_ParentID]) )
	AND ( [ProductClassification_Code] like ISNULL(@ProductClassification_Code, [ProductClassification_Code]) )
	AND ( [ProductClassification_NameAr] like ISNULL(@ProductClassification_NameAr, [ProductClassification_NameAr]) )
	AND ( [ProductClassification_NameEn] like ISNULL(@ProductClassification_NameEn, [ProductClassification_NameEn]) )
	AND ( [ProductClassification_Notes] like ISNULL(@ProductClassification_Notes, [ProductClassification_Notes]) )
	AND ( [ProductClassification_Search] like ISNULL(@ProductClassification_Search, [ProductClassification_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products-Insert]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	Insert record into table [dbo].[Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products-Insert]
	/*@Product_RowNumber int =Null OUTPUT , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Code varchar(50) =Null  , 
	@ProductClassification_ID uniqueidentifier =Null  , 
	@Product_NameAr varchar(300) =Null  , 
	@Product_NameEn varchar(300) =Null  , 
	@Product_Notes varchar(max) =Null  , 
	@Product_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Products](/*[Product_ID], [Product_Code], [ProductClassification_ID], [Product_NameAr], [Product_NameEn], [Product_Notes], [Product_Search]*/)
	VALUES     (/*@Product_ID, @Product_Code, @ProductClassification_ID, @Product_NameAr, @Product_NameEn, @Product_Notes, @Product_Search*/)

	/*SELECT @Product_RowNumber = [Product_RowNumber]
    FROM [dbo].[Products]
    WHERE  ( [Product_ID] =@Product_ID )
	AND  ( [Product_Code] =@Product_Code )
	AND  ( [ProductClassification_ID] =@ProductClassification_ID )
	AND  ( [Product_NameAr] =@Product_NameAr )
	AND  ( [Product_NameEn] =@Product_NameEn )
	AND  ( [Product_Notes] =@Product_Notes )
	AND  ( [Product_Search] =@Product_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products-update]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	Update record in table [dbo].[Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products-update]
	/*@Product_RowNumber int =Null OUTPUT , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Code varchar(50) =Null  , 
	@ProductClassification_ID uniqueidentifier =Null  , 
	@Product_NameAr varchar(300) =Null  , 
	@Product_NameEn varchar(300) =Null  , 
	@Product_Notes varchar(max) =Null  , 
	@Product_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Products] SET 
		/*[Product_ID] =@Product_ID, 
		[Product_Code] =@Product_Code, 
		[ProductClassification_ID] =@ProductClassification_ID, 
		[Product_NameAr] =@Product_NameAr, 
		[Product_NameEn] =@Product_NameEn, 
		[Product_Notes] =@Product_Notes, 
		[Product_Search] =@Product_Search*/
		/*WHERE ([Product_ID] = @Product_ID)*/
	/**/

	/*SELECT @Product_RowNumber = [Product_RowNumber]
    FROM [dbo].[Products]
	WHERE ([Product_ID] = @Product_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products-Insert-Update]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	Insert OR Update record into table [dbo].[Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products-Insert-Update]
	/*@Product_RowNumber int =Null OUTPUT , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Code varchar(50) =Null  , 
	@ProductClassification_ID uniqueidentifier =Null  , 
	@Product_NameAr varchar(300) =Null  , 
	@Product_NameEn varchar(300) =Null  , 
	@Product_Notes varchar(max) =Null  , 
	@Product_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Products] 
					/*WHERE ([Product_ID] = @Product_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Products](/*[Product_ID], [Product_Code], [ProductClassification_ID], [Product_NameAr], [Product_NameEn], [Product_Notes], [Product_Search]*/)
		VALUES     (/*@Product_ID, @Product_Code, @ProductClassification_ID, @Product_NameAr, @Product_NameEn, @Product_Notes, @Product_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Products] SET 
			/*[Product_ID] =@Product_ID, 
			[Product_Code] =@Product_Code, 
			[ProductClassification_ID] =@ProductClassification_ID, 
			[Product_NameAr] =@Product_NameAr, 
			[Product_NameEn] =@Product_NameEn, 
			[Product_Notes] =@Product_Notes, 
			[Product_Search] =@Product_Search*/
			/*WHERE ([Product_ID] = @Product_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Product_RowNumber = [Product_RowNumber]
    FROM [dbo].[Products]
	WHERE ([Product_ID] = @Product_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products-Delete]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	delete records from table [dbo].[Products] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products-Delete]
	/*@Product_RowNumber int =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Product_Code varchar(50) =null  , 
	@ProductClassification_ID uniqueidentifier =null  , 
	@Product_NameAr varchar(300) =null  , 
	@Product_NameEn varchar(300) =null  , 
	@Product_Notes varchar(max) =null  , 
	@Product_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Products]
	WHERE /*( [Product_RowNumber] = ISNULL(@Product_RowNumber, [Product_RowNumber]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Product_Code] like ISNULL(@Product_Code, [Product_Code]) )
	AND ( [ProductClassification_ID] = ISNULL(@ProductClassification_ID, [ProductClassification_ID]) )
	AND ( [Product_NameAr] like ISNULL(@Product_NameAr, [Product_NameAr]) )
	AND ( [Product_NameEn] like ISNULL(@Product_NameEn, [Product_NameEn]) )
	AND ( [Product_Notes] like ISNULL(@Product_Notes, [Product_Notes]) )
	AND ( [Product_Search] like ISNULL(@Product_Search, [Product_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products-Select]    Script Date: [[20120714223937]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223937]]
-- Description:	select records from table [dbo].[Products] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products-Select]
	/*@Product_RowNumber int =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Product_Code varchar(50) =null  , 
	@ProductClassification_ID uniqueidentifier =null  , 
	@Product_NameAr varchar(300) =null  , 
	@Product_NameEn varchar(300) =null  , 
	@Product_Notes varchar(max) =null  , 
	@Product_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Products]
	WHERE /*( [Product_RowNumber] = ISNULL(@Product_RowNumber, [Product_RowNumber]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Product_Code] like ISNULL(@Product_Code, [Product_Code]) )
	AND ( [ProductClassification_ID] = ISNULL(@ProductClassification_ID, [ProductClassification_ID]) )
	AND ( [Product_NameAr] like ISNULL(@Product_NameAr, [Product_NameAr]) )
	AND ( [Product_NameEn] like ISNULL(@Product_NameEn, [Product_NameEn]) )
	AND ( [Product_Notes] like ISNULL(@Product_Notes, [Product_Notes]) )
	AND ( [Product_Search] like ISNULL(@Product_Search, [Product_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products_MeasureUnits-Insert]    Script Date: [[20120714223938]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223938]]
-- Description:	Insert record into table [dbo].[Products_MeasureUnits]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products_MeasureUnits-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products_MeasureUnits-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products_MeasureUnits-Insert]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@ParentMeasureUnit_ID uniqueidentifier =Null  , 
	@ParentQuantity float =Null  , 
	@Notes varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Products_MeasureUnits](/*[ID], [Product_ID], [MeasureUnit_ID], [ParentMeasureUnit_ID], [ParentQuantity], [Notes]*/)
	VALUES     (/*@ID, @Product_ID, @MeasureUnit_ID, @ParentMeasureUnit_ID, @ParentQuantity, @Notes*/)

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Products_MeasureUnits]
    WHERE  ( [ID] =@ID )
	AND  ( [Product_ID] =@Product_ID )
	AND  ( [MeasureUnit_ID] =@MeasureUnit_ID )
	AND  ( [ParentMeasureUnit_ID] =@ParentMeasureUnit_ID )
	AND  ( [ParentQuantity] =@ParentQuantity )
	AND  ( [Notes] =@Notes )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products_MeasureUnits-update]    Script Date: [[20120714223938]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223938]]
-- Description:	Update record in table [dbo].[Products_MeasureUnits]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products_MeasureUnits-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products_MeasureUnits-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products_MeasureUnits-update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@ParentMeasureUnit_ID uniqueidentifier =Null  , 
	@ParentQuantity float =Null  , 
	@Notes varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Products_MeasureUnits] SET 
		/*[ID] =@ID, 
		[Product_ID] =@Product_ID, 
		[MeasureUnit_ID] =@MeasureUnit_ID, 
		[ParentMeasureUnit_ID] =@ParentMeasureUnit_ID, 
		[ParentQuantity] =@ParentQuantity, 
		[Notes] =@Notes*/
		/*WHERE ([ID] = @ID)*/
	/**/

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Products_MeasureUnits]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products_MeasureUnits-Insert-Update]    Script Date: [[20120714223938]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223938]]
-- Description:	Insert OR Update record into table [dbo].[Products_MeasureUnits]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products_MeasureUnits-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products_MeasureUnits-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products_MeasureUnits-Insert-Update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@ParentMeasureUnit_ID uniqueidentifier =Null  , 
	@ParentQuantity float =Null  , 
	@Notes varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Products_MeasureUnits] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Products_MeasureUnits](/*[ID], [Product_ID], [MeasureUnit_ID], [ParentMeasureUnit_ID], [ParentQuantity], [Notes]*/)
		VALUES     (/*@ID, @Product_ID, @MeasureUnit_ID, @ParentMeasureUnit_ID, @ParentQuantity, @Notes*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Products_MeasureUnits] SET 
			/*[ID] =@ID, 
			[Product_ID] =@Product_ID, 
			[MeasureUnit_ID] =@MeasureUnit_ID, 
			[ParentMeasureUnit_ID] =@ParentMeasureUnit_ID, 
			[ParentQuantity] =@ParentQuantity, 
			[Notes] =@Notes*/
			/*WHERE ([ID] = @ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Products_MeasureUnits]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products_MeasureUnits-Delete]    Script Date: [[20120714223938]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223938]]
-- Description:	delete records from table [dbo].[Products_MeasureUnits] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products_MeasureUnits-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products_MeasureUnits-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products_MeasureUnits-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@ParentMeasureUnit_ID uniqueidentifier =null  , 
	@ParentQuantity float =null  , 
	@Notes varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Products_MeasureUnits]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [ParentMeasureUnit_ID] = ISNULL(@ParentMeasureUnit_ID, [ParentMeasureUnit_ID]) )
	AND ( [ParentQuantity] = ISNULL(@ParentQuantity, [ParentQuantity]) )
	AND ( [Notes] like ISNULL(@Notes, [Notes]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products_MeasureUnits-Select]    Script Date: [[20120714223938]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223938]]
-- Description:	select records from table [dbo].[Products_MeasureUnits] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products_MeasureUnits-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products_MeasureUnits-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products_MeasureUnits-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@ParentMeasureUnit_ID uniqueidentifier =null  , 
	@ParentQuantity float =null  , 
	@Notes varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Products_MeasureUnits]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [ParentMeasureUnit_ID] = ISNULL(@ParentMeasureUnit_ID, [ParentMeasureUnit_ID]) )
	AND ( [ParentQuantity] = ISNULL(@ParentQuantity, [ParentQuantity]) )
	AND ( [Notes] like ISNULL(@Notes, [Notes]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores-Insert]    Script Date: [[20120714223939]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223939]]
-- Description:	Insert record into table [dbo].[Stores]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores-Insert]
	/*@Store_RowNumber int =Null OUTPUT , 
	@Store_ID uniqueidentifier =Null  , 
	@StoreClassification_ID uniqueidentifier =Null  , 
	@Store_Code varchar(50) =Null  , 
	@Store_NameAr varchar(300) =Null  , 
	@Store_NameEn varchar(300) =Null  , 
	@Store_Address varchar(500) =Null  , 
	@Store_Notes varchar(max) =Null  , 
	@IsSellPlace tinyint =0  , 
	@Store_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Stores](/*[Store_ID], [StoreClassification_ID], [Store_Code], [Store_NameAr], [Store_NameEn], [Store_Address], [Store_Notes], [IsSellPlace], [Store_Search]*/)
	VALUES     (/*@Store_ID, @StoreClassification_ID, @Store_Code, @Store_NameAr, @Store_NameEn, @Store_Address, @Store_Notes, @IsSellPlace, @Store_Search*/)

	/*SELECT @Store_RowNumber = [Store_RowNumber]
    FROM [dbo].[Stores]
    WHERE  ( [Store_ID] =@Store_ID )
	AND  ( [StoreClassification_ID] =@StoreClassification_ID )
	AND  ( [Store_Code] =@Store_Code )
	AND  ( [Store_NameAr] =@Store_NameAr )
	AND  ( [Store_NameEn] =@Store_NameEn )
	AND  ( [Store_Address] =@Store_Address )
	AND  ( [Store_Notes] =@Store_Notes )
	AND  ( [IsSellPlace] =@IsSellPlace )
	AND  ( [Store_Search] =@Store_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores-update]    Script Date: [[20120714223939]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223939]]
-- Description:	Update record in table [dbo].[Stores]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores-update]
	/*@Store_RowNumber int =Null OUTPUT , 
	@Store_ID uniqueidentifier =Null  , 
	@StoreClassification_ID uniqueidentifier =Null  , 
	@Store_Code varchar(50) =Null  , 
	@Store_NameAr varchar(300) =Null  , 
	@Store_NameEn varchar(300) =Null  , 
	@Store_Address varchar(500) =Null  , 
	@Store_Notes varchar(max) =Null  , 
	@IsSellPlace tinyint =0  , 
	@Store_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Stores] SET 
		/*[Store_ID] =@Store_ID, 
		[StoreClassification_ID] =@StoreClassification_ID, 
		[Store_Code] =@Store_Code, 
		[Store_NameAr] =@Store_NameAr, 
		[Store_NameEn] =@Store_NameEn, 
		[Store_Address] =@Store_Address, 
		[Store_Notes] =@Store_Notes, 
		[IsSellPlace] =@IsSellPlace, 
		[Store_Search] =@Store_Search*/
		/*WHERE ([Store_ID] = @Store_ID)*/
	/**/

	/*SELECT @Store_RowNumber = [Store_RowNumber]
    FROM [dbo].[Stores]
	WHERE ([Store_ID] = @Store_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores-Insert-Update]    Script Date: [[20120714223939]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223939]]
-- Description:	Insert OR Update record into table [dbo].[Stores]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores-Insert-Update]
	/*@Store_RowNumber int =Null OUTPUT , 
	@Store_ID uniqueidentifier =Null  , 
	@StoreClassification_ID uniqueidentifier =Null  , 
	@Store_Code varchar(50) =Null  , 
	@Store_NameAr varchar(300) =Null  , 
	@Store_NameEn varchar(300) =Null  , 
	@Store_Address varchar(500) =Null  , 
	@Store_Notes varchar(max) =Null  , 
	@IsSellPlace tinyint =0  , 
	@Store_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Stores] 
					/*WHERE ([Store_ID] = @Store_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Stores](/*[Store_ID], [StoreClassification_ID], [Store_Code], [Store_NameAr], [Store_NameEn], [Store_Address], [Store_Notes], [IsSellPlace], [Store_Search]*/)
		VALUES     (/*@Store_ID, @StoreClassification_ID, @Store_Code, @Store_NameAr, @Store_NameEn, @Store_Address, @Store_Notes, @IsSellPlace, @Store_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Stores] SET 
			/*[Store_ID] =@Store_ID, 
			[StoreClassification_ID] =@StoreClassification_ID, 
			[Store_Code] =@Store_Code, 
			[Store_NameAr] =@Store_NameAr, 
			[Store_NameEn] =@Store_NameEn, 
			[Store_Address] =@Store_Address, 
			[Store_Notes] =@Store_Notes, 
			[IsSellPlace] =@IsSellPlace, 
			[Store_Search] =@Store_Search*/
			/*WHERE ([Store_ID] = @Store_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Store_RowNumber = [Store_RowNumber]
    FROM [dbo].[Stores]
	WHERE ([Store_ID] = @Store_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores-Delete]    Script Date: [[20120714223939]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223939]]
-- Description:	delete records from table [dbo].[Stores] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores-Delete]
	/*@Store_RowNumber int =null  , 
	@Store_ID uniqueidentifier =null  , 
	@StoreClassification_ID uniqueidentifier =null  , 
	@Store_Code varchar(50) =null  , 
	@Store_NameAr varchar(300) =null  , 
	@Store_NameEn varchar(300) =null  , 
	@Store_Address varchar(500) =null  , 
	@Store_Notes varchar(max) =null  , 
	@IsSellPlace tinyint =null  , 
	@Store_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Stores]
	WHERE /*( [Store_RowNumber] = ISNULL(@Store_RowNumber, [Store_RowNumber]) )
	AND ( [Store_ID] = ISNULL(@Store_ID, [Store_ID]) )
	AND ( [StoreClassification_ID] = ISNULL(@StoreClassification_ID, [StoreClassification_ID]) )
	AND ( [Store_Code] like ISNULL(@Store_Code, [Store_Code]) )
	AND ( [Store_NameAr] like ISNULL(@Store_NameAr, [Store_NameAr]) )
	AND ( [Store_NameEn] like ISNULL(@Store_NameEn, [Store_NameEn]) )
	AND ( [Store_Address] like ISNULL(@Store_Address, [Store_Address]) )
	AND ( [Store_Notes] like ISNULL(@Store_Notes, [Store_Notes]) )
	AND ( [IsSellPlace] = ISNULL(@IsSellPlace, [IsSellPlace]) )
	AND ( [Store_Search] like ISNULL(@Store_Search, [Store_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores-Select]    Script Date: [[20120714223939]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223939]]
-- Description:	select records from table [dbo].[Stores] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores-Select]
	/*@Store_RowNumber int =null  , 
	@Store_ID uniqueidentifier =null  , 
	@StoreClassification_ID uniqueidentifier =null  , 
	@Store_Code varchar(50) =null  , 
	@Store_NameAr varchar(300) =null  , 
	@Store_NameEn varchar(300) =null  , 
	@Store_Address varchar(500) =null  , 
	@Store_Notes varchar(max) =null  , 
	@IsSellPlace tinyint =null  , 
	@Store_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Stores]
	WHERE /*( [Store_RowNumber] = ISNULL(@Store_RowNumber, [Store_RowNumber]) )
	AND ( [Store_ID] = ISNULL(@Store_ID, [Store_ID]) )
	AND ( [StoreClassification_ID] = ISNULL(@StoreClassification_ID, [StoreClassification_ID]) )
	AND ( [Store_Code] like ISNULL(@Store_Code, [Store_Code]) )
	AND ( [Store_NameAr] like ISNULL(@Store_NameAr, [Store_NameAr]) )
	AND ( [Store_NameEn] like ISNULL(@Store_NameEn, [Store_NameEn]) )
	AND ( [Store_Address] like ISNULL(@Store_Address, [Store_Address]) )
	AND ( [Store_Notes] like ISNULL(@Store_Notes, [Store_Notes]) )
	AND ( [IsSellPlace] = ISNULL(@IsSellPlace, [IsSellPlace]) )
	AND ( [Store_Search] like ISNULL(@Store_Search, [Store_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores_Products-Insert]    Script Date: [[20120714223940]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223940]]
-- Description:	Insert record into table [dbo].[Stores_Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores_Products-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores_Products-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores_Products-Insert]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Quantity float =Null  , 
	@Product_Price float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@SafetyLimit float =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Stores_Products](/*[ID], [Store_ID], [Product_ID], [Product_Quantity], [Product_Price], [MeasureUnit_ID], [SafetyLimit]*/)
	VALUES     (/*@ID, @Store_ID, @Product_ID, @Product_Quantity, @Product_Price, @MeasureUnit_ID, @SafetyLimit*/)

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Stores_Products]
    WHERE  ( [ID] =@ID )
	AND  ( [Store_ID] =@Store_ID )
	AND  ( [Product_ID] =@Product_ID )
	AND  ( [Product_Quantity] =@Product_Quantity )
	AND  ( [Product_Price] =@Product_Price )
	AND  ( [MeasureUnit_ID] =@MeasureUnit_ID )
	AND  ( [SafetyLimit] =@SafetyLimit )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores_Products-update]    Script Date: [[20120714223940]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223940]]
-- Description:	Update record in table [dbo].[Stores_Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores_Products-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores_Products-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores_Products-update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Quantity float =Null  , 
	@Product_Price float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@SafetyLimit float =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Stores_Products] SET 
		/*[ID] =@ID, 
		[Store_ID] =@Store_ID, 
		[Product_ID] =@Product_ID, 
		[Product_Quantity] =@Product_Quantity, 
		[Product_Price] =@Product_Price, 
		[MeasureUnit_ID] =@MeasureUnit_ID, 
		[SafetyLimit] =@SafetyLimit*/
		/*WHERE ([ID] = @ID)*/
	/**/

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Stores_Products]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores_Products-Insert-Update]    Script Date: [[20120714223940]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223940]]
-- Description:	Insert OR Update record into table [dbo].[Stores_Products]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores_Products-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores_Products-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores_Products-Insert-Update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Quantity float =Null  , 
	@Product_Price float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@SafetyLimit float =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Stores_Products] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Stores_Products](/*[ID], [Store_ID], [Product_ID], [Product_Quantity], [Product_Price], [MeasureUnit_ID], [SafetyLimit]*/)
		VALUES     (/*@ID, @Store_ID, @Product_ID, @Product_Quantity, @Product_Price, @MeasureUnit_ID, @SafetyLimit*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Stores_Products] SET 
			/*[ID] =@ID, 
			[Store_ID] =@Store_ID, 
			[Product_ID] =@Product_ID, 
			[Product_Quantity] =@Product_Quantity, 
			[Product_Price] =@Product_Price, 
			[MeasureUnit_ID] =@MeasureUnit_ID, 
			[SafetyLimit] =@SafetyLimit*/
			/*WHERE ([ID] = @ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Stores_Products]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores_Products-Delete]    Script Date: [[20120714223940]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223940]]
-- Description:	delete records from table [dbo].[Stores_Products] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores_Products-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores_Products-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores_Products-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Store_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Product_Quantity float =null  , 
	@Product_Price float =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@SafetyLimit float =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Stores_Products]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Store_ID] = ISNULL(@Store_ID, [Store_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Product_Quantity] = ISNULL(@Product_Quantity, [Product_Quantity]) )
	AND ( [Product_Price] = ISNULL(@Product_Price, [Product_Price]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [SafetyLimit] = ISNULL(@SafetyLimit, [SafetyLimit]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Stores_Products-Select]    Script Date: [[20120714223940]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223940]]
-- Description:	select records from table [dbo].[Stores_Products] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Stores_Products-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Stores_Products-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Stores_Products-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Store_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Product_Quantity float =null  , 
	@Product_Price float =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@SafetyLimit float =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Stores_Products]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Store_ID] = ISNULL(@Store_ID, [Store_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Product_Quantity] = ISNULL(@Product_Quantity, [Product_Quantity]) )
	AND ( [Product_Price] = ISNULL(@Product_Price, [Product_Price]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [SafetyLimit] = ISNULL(@SafetyLimit, [SafetyLimit]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[StoresClassifications-Insert]    Script Date: [[20120714223941]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223941]]
-- Description:	Insert record into table [dbo].[StoresClassifications]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[StoresClassifications-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[StoresClassifications-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[StoresClassifications-Insert]
	/*@StoreClassification_RowNumber int =Null OUTPUT , 
	@StoreClassification_ID uniqueidentifier =Null  , 
	@StoreClassification_ParentID uniqueidentifier =Null  , 
	@StoreClassification_Code varchar(50) =Null  , 
	@StoreClassification_NameAr varchar(300) =Null  , 
	@StoreClassification_NameEn varchar(300) =Null  , 
	@StoreClassification_Notes varchar(max) =Null  , 
	@StoreClassification_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[StoresClassifications](/*[StoreClassification_ID], [StoreClassification_ParentID], [StoreClassification_Code], [StoreClassification_NameAr], [StoreClassification_NameEn], [StoreClassification_Notes], [StoreClassification_Search]*/)
	VALUES     (/*@StoreClassification_ID, @StoreClassification_ParentID, @StoreClassification_Code, @StoreClassification_NameAr, @StoreClassification_NameEn, @StoreClassification_Notes, @StoreClassification_Search*/)

	/*SELECT @StoreClassification_RowNumber = [StoreClassification_RowNumber]
    FROM [dbo].[StoresClassifications]
    WHERE  ( [StoreClassification_ID] =@StoreClassification_ID )
	AND  ( [StoreClassification_ParentID] =@StoreClassification_ParentID )
	AND  ( [StoreClassification_Code] =@StoreClassification_Code )
	AND  ( [StoreClassification_NameAr] =@StoreClassification_NameAr )
	AND  ( [StoreClassification_NameEn] =@StoreClassification_NameEn )
	AND  ( [StoreClassification_Notes] =@StoreClassification_Notes )
	AND  ( [StoreClassification_Search] =@StoreClassification_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[StoresClassifications-update]    Script Date: [[20120714223941]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223941]]
-- Description:	Update record in table [dbo].[StoresClassifications]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[StoresClassifications-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[StoresClassifications-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[StoresClassifications-update]
	/*@StoreClassification_RowNumber int =Null OUTPUT , 
	@StoreClassification_ID uniqueidentifier =Null  , 
	@StoreClassification_ParentID uniqueidentifier =Null  , 
	@StoreClassification_Code varchar(50) =Null  , 
	@StoreClassification_NameAr varchar(300) =Null  , 
	@StoreClassification_NameEn varchar(300) =Null  , 
	@StoreClassification_Notes varchar(max) =Null  , 
	@StoreClassification_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[StoresClassifications] SET 
		/*[StoreClassification_ID] =@StoreClassification_ID, 
		[StoreClassification_ParentID] =@StoreClassification_ParentID, 
		[StoreClassification_Code] =@StoreClassification_Code, 
		[StoreClassification_NameAr] =@StoreClassification_NameAr, 
		[StoreClassification_NameEn] =@StoreClassification_NameEn, 
		[StoreClassification_Notes] =@StoreClassification_Notes, 
		[StoreClassification_Search] =@StoreClassification_Search*/
		/*WHERE ([StoreClassification_ID] = @StoreClassification_ID)*/
	/**/

	/*SELECT @StoreClassification_RowNumber = [StoreClassification_RowNumber]
    FROM [dbo].[StoresClassifications]
	WHERE ([StoreClassification_ID] = @StoreClassification_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[StoresClassifications-Insert-Update]    Script Date: [[20120714223941]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223941]]
-- Description:	Insert OR Update record into table [dbo].[StoresClassifications]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[StoresClassifications-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[StoresClassifications-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[StoresClassifications-Insert-Update]
	/*@StoreClassification_RowNumber int =Null OUTPUT , 
	@StoreClassification_ID uniqueidentifier =Null  , 
	@StoreClassification_ParentID uniqueidentifier =Null  , 
	@StoreClassification_Code varchar(50) =Null  , 
	@StoreClassification_NameAr varchar(300) =Null  , 
	@StoreClassification_NameEn varchar(300) =Null  , 
	@StoreClassification_Notes varchar(max) =Null  , 
	@StoreClassification_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[StoresClassifications] 
					/*WHERE ([StoreClassification_ID] = @StoreClassification_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[StoresClassifications](/*[StoreClassification_ID], [StoreClassification_ParentID], [StoreClassification_Code], [StoreClassification_NameAr], [StoreClassification_NameEn], [StoreClassification_Notes], [StoreClassification_Search]*/)
		VALUES     (/*@StoreClassification_ID, @StoreClassification_ParentID, @StoreClassification_Code, @StoreClassification_NameAr, @StoreClassification_NameEn, @StoreClassification_Notes, @StoreClassification_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[StoresClassifications] SET 
			/*[StoreClassification_ID] =@StoreClassification_ID, 
			[StoreClassification_ParentID] =@StoreClassification_ParentID, 
			[StoreClassification_Code] =@StoreClassification_Code, 
			[StoreClassification_NameAr] =@StoreClassification_NameAr, 
			[StoreClassification_NameEn] =@StoreClassification_NameEn, 
			[StoreClassification_Notes] =@StoreClassification_Notes, 
			[StoreClassification_Search] =@StoreClassification_Search*/
			/*WHERE ([StoreClassification_ID] = @StoreClassification_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @StoreClassification_RowNumber = [StoreClassification_RowNumber]
    FROM [dbo].[StoresClassifications]
	WHERE ([StoreClassification_ID] = @StoreClassification_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[StoresClassifications-Delete]    Script Date: [[20120714223941]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223941]]
-- Description:	delete records from table [dbo].[StoresClassifications] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[StoresClassifications-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[StoresClassifications-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[StoresClassifications-Delete]
	/*@StoreClassification_RowNumber int =null  , 
	@StoreClassification_ID uniqueidentifier =null  , 
	@StoreClassification_ParentID uniqueidentifier =null  , 
	@StoreClassification_Code varchar(50) =null  , 
	@StoreClassification_NameAr varchar(300) =null  , 
	@StoreClassification_NameEn varchar(300) =null  , 
	@StoreClassification_Notes varchar(max) =null  , 
	@StoreClassification_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[StoresClassifications]
	WHERE /*( [StoreClassification_RowNumber] = ISNULL(@StoreClassification_RowNumber, [StoreClassification_RowNumber]) )
	AND ( [StoreClassification_ID] = ISNULL(@StoreClassification_ID, [StoreClassification_ID]) )
	AND ( [StoreClassification_ParentID] = ISNULL(@StoreClassification_ParentID, [StoreClassification_ParentID]) )
	AND ( [StoreClassification_Code] like ISNULL(@StoreClassification_Code, [StoreClassification_Code]) )
	AND ( [StoreClassification_NameAr] like ISNULL(@StoreClassification_NameAr, [StoreClassification_NameAr]) )
	AND ( [StoreClassification_NameEn] like ISNULL(@StoreClassification_NameEn, [StoreClassification_NameEn]) )
	AND ( [StoreClassification_Notes] like ISNULL(@StoreClassification_Notes, [StoreClassification_Notes]) )
	AND ( [StoreClassification_Search] like ISNULL(@StoreClassification_Search, [StoreClassification_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[StoresClassifications-Select]    Script Date: [[20120714223941]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223941]]
-- Description:	select records from table [dbo].[StoresClassifications] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[StoresClassifications-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[StoresClassifications-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[StoresClassifications-Select]
	/*@StoreClassification_RowNumber int =null  , 
	@StoreClassification_ID uniqueidentifier =null  , 
	@StoreClassification_ParentID uniqueidentifier =null  , 
	@StoreClassification_Code varchar(50) =null  , 
	@StoreClassification_NameAr varchar(300) =null  , 
	@StoreClassification_NameEn varchar(300) =null  , 
	@StoreClassification_Notes varchar(max) =null  , 
	@StoreClassification_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[StoresClassifications]
	WHERE /*( [StoreClassification_RowNumber] = ISNULL(@StoreClassification_RowNumber, [StoreClassification_RowNumber]) )
	AND ( [StoreClassification_ID] = ISNULL(@StoreClassification_ID, [StoreClassification_ID]) )
	AND ( [StoreClassification_ParentID] = ISNULL(@StoreClassification_ParentID, [StoreClassification_ParentID]) )
	AND ( [StoreClassification_Code] like ISNULL(@StoreClassification_Code, [StoreClassification_Code]) )
	AND ( [StoreClassification_NameAr] like ISNULL(@StoreClassification_NameAr, [StoreClassification_NameAr]) )
	AND ( [StoreClassification_NameEn] like ISNULL(@StoreClassification_NameEn, [StoreClassification_NameEn]) )
	AND ( [StoreClassification_Notes] like ISNULL(@StoreClassification_Notes, [StoreClassification_Notes]) )
	AND ( [StoreClassification_Search] like ISNULL(@StoreClassification_Search, [StoreClassification_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[sysdiagrams-Insert]    Script Date: [[20120714223941]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223941]]
-- Description:	Insert record into table [dbo].[sysdiagrams]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[sysdiagrams-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[sysdiagrams-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[sysdiagrams-Insert]
	/*@name nvarchar(128) =Null  , 
	@principal_id int =Null  , 
	@diagram_id int =Null OUTPUT , 
	@version int =Null  , 
	@definition varbinary =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[sysdiagrams](/*[name], [principal_id], [version], [definition]*/)
	VALUES     (/*@name, @principal_id, @version, @definition*/)

	/*SELECT @diagram_id = [diagram_id]
    FROM [dbo].[sysdiagrams]
    WHERE  ( [name] =@name )
	AND  ( [principal_id] =@principal_id )
	AND  ( [version] =@version )
	AND  ( [definition] =@definition )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[sysdiagrams-update]    Script Date: [[20120714223941]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223941]]
-- Description:	Update record in table [dbo].[sysdiagrams]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[sysdiagrams-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[sysdiagrams-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[sysdiagrams-update]
	/*@name nvarchar(128) =Null  , 
	@principal_id int =Null  , 
	@diagram_id int =Null OUTPUT , 
	@version int =Null  , 
	@definition varbinary =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[sysdiagrams] SET 
		/*[name] =@name, 
		[principal_id] =@principal_id, 
		[version] =@version, 
		[definition] =@definition*/
		/*WHERE ([diagram_id] = @diagram_id)*/
	/**/

	/*SELECT @diagram_id = [diagram_id]
    FROM [dbo].[sysdiagrams]
	WHERE ([diagram_id] = @diagram_id)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[sysdiagrams-Insert-Update]    Script Date: [[20120714223942]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223942]]
-- Description:	Insert OR Update record into table [dbo].[sysdiagrams]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[sysdiagrams-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[sysdiagrams-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[sysdiagrams-Insert-Update]
	/*@name nvarchar(128) =Null  , 
	@principal_id int =Null  , 
	@diagram_id int =Null OUTPUT , 
	@version int =Null  , 
	@definition varbinary =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[sysdiagrams] 
					/*WHERE ([diagram_id] = @diagram_id)*/)
	BEGIN
		
		INSERT  INTO [dbo].[sysdiagrams](/*[name], [principal_id], [version], [definition]*/)
		VALUES     (/*@name, @principal_id, @version, @definition*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[sysdiagrams] SET 
			/*[name] =@name, 
			[principal_id] =@principal_id, 
			[version] =@version, 
			[definition] =@definition*/
			/*WHERE ([diagram_id] = @diagram_id)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @diagram_id = [diagram_id]
    FROM [dbo].[sysdiagrams]
	WHERE ([diagram_id] = @diagram_id)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[sysdiagrams-Delete]    Script Date: [[20120714223942]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223942]]
-- Description:	delete records from table [dbo].[sysdiagrams] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[sysdiagrams-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[sysdiagrams-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[sysdiagrams-Delete]
	/*@name nvarchar(128) =null  , 
	@principal_id int =null  , 
	@diagram_id int =null  , 
	@version int =null  , 
	@definition varbinary =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[sysdiagrams]
	WHERE /*( [name] like ISNULL(@name, [name]) )
	AND ( [principal_id] = ISNULL(@principal_id, [principal_id]) )
	AND ( [diagram_id] = ISNULL(@diagram_id, [diagram_id]) )
	AND ( [version] = ISNULL(@version, [version]) )
	AND ( [definition] = ISNULL(@definition, [definition]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[sysdiagrams-Select]    Script Date: [[20120714223942]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223942]]
-- Description:	select records from table [dbo].[sysdiagrams] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[sysdiagrams-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[sysdiagrams-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[sysdiagrams-Select]
	/*@name nvarchar(128) =null  , 
	@principal_id int =null  , 
	@diagram_id int =null  , 
	@version int =null  , 
	@definition varbinary =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[sysdiagrams]
	WHERE /*( [name] like ISNULL(@name, [name]) )
	AND ( [principal_id] = ISNULL(@principal_id, [principal_id]) )
	AND ( [diagram_id] = ISNULL(@diagram_id, [diagram_id]) )
	AND ( [version] = ISNULL(@version, [version]) )
	AND ( [definition] = ISNULL(@definition, [definition]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[TablesNames-Insert]    Script Date: [[20120714223942]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223942]]
-- Description:	Insert record into table [dbo].[TablesNames]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[TablesNames-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[TablesNames-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[TablesNames-Insert]
	/*@TableName_RowNumber int =Null  , 
	@TableName_ID uniqueidentifier =Null  , 
	@TableName_NameAr varchar(200) =Null  , 
	@TableName_NameEn varchar(200) =Null  , 
	@TableName_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[TablesNames](/*[TableName_RowNumber], [TableName_ID], [TableName_NameAr], [TableName_NameEn], [TableName_Search]*/)
	VALUES     (/*@TableName_RowNumber, @TableName_ID, @TableName_NameAr, @TableName_NameEn, @TableName_Search*/)

	/**/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[TablesNames-update]    Script Date: [[20120714223942]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223942]]
-- Description:	Update record in table [dbo].[TablesNames]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[TablesNames-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[TablesNames-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[TablesNames-update]
	/*@TableName_RowNumber int =Null  , 
	@TableName_ID uniqueidentifier =Null  , 
	@TableName_NameAr varchar(200) =Null  , 
	@TableName_NameEn varchar(200) =Null  , 
	@TableName_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[TablesNames] SET 
		/*[TableName_RowNumber] =@TableName_RowNumber, 
		[TableName_ID] =@TableName_ID, 
		[TableName_NameAr] =@TableName_NameAr, 
		[TableName_NameEn] =@TableName_NameEn, 
		[TableName_Search] =@TableName_Search*/
		/*WHERE ([TableName_ID] = @TableName_ID)*/
	/**/

	/**/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[TablesNames-Insert-Update]    Script Date: [[20120714223942]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223942]]
-- Description:	Insert OR Update record into table [dbo].[TablesNames]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[TablesNames-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[TablesNames-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[TablesNames-Insert-Update]
	/*@TableName_RowNumber int =Null  , 
	@TableName_ID uniqueidentifier =Null  , 
	@TableName_NameAr varchar(200) =Null  , 
	@TableName_NameEn varchar(200) =Null  , 
	@TableName_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[TablesNames] 
					/*WHERE ([TableName_ID] = @TableName_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[TablesNames](/*[TableName_RowNumber], [TableName_ID], [TableName_NameAr], [TableName_NameEn], [TableName_Search]*/)
		VALUES     (/*@TableName_RowNumber, @TableName_ID, @TableName_NameAr, @TableName_NameEn, @TableName_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[TablesNames] SET 
			/*[TableName_RowNumber] =@TableName_RowNumber, 
			[TableName_ID] =@TableName_ID, 
			[TableName_NameAr] =@TableName_NameAr, 
			[TableName_NameEn] =@TableName_NameEn, 
			[TableName_Search] =@TableName_Search*/
			/*WHERE ([TableName_ID] = @TableName_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/**/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[TablesNames-Delete]    Script Date: [[20120714223942]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223942]]
-- Description:	delete records from table [dbo].[TablesNames] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[TablesNames-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[TablesNames-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[TablesNames-Delete]
	/*@TableName_RowNumber int =null  , 
	@TableName_ID uniqueidentifier =null  , 
	@TableName_NameAr varchar(200) =null  , 
	@TableName_NameEn varchar(200) =null  , 
	@TableName_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[TablesNames]
	WHERE /*( [TableName_RowNumber] = ISNULL(@TableName_RowNumber, [TableName_RowNumber]) )
	AND ( [TableName_ID] = ISNULL(@TableName_ID, [TableName_ID]) )
	AND ( [TableName_NameAr] like ISNULL(@TableName_NameAr, [TableName_NameAr]) )
	AND ( [TableName_NameEn] like ISNULL(@TableName_NameEn, [TableName_NameEn]) )
	AND ( [TableName_Search] like ISNULL(@TableName_Search, [TableName_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[TablesNames-Select]    Script Date: [[20120714223942]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223942]]
-- Description:	select records from table [dbo].[TablesNames] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[TablesNames-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[TablesNames-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[TablesNames-Select]
	/*@TableName_RowNumber int =null  , 
	@TableName_ID uniqueidentifier =null  , 
	@TableName_NameAr varchar(200) =null  , 
	@TableName_NameEn varchar(200) =null  , 
	@TableName_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[TablesNames]
	WHERE /*( [TableName_RowNumber] = ISNULL(@TableName_RowNumber, [TableName_RowNumber]) )
	AND ( [TableName_ID] = ISNULL(@TableName_ID, [TableName_ID]) )
	AND ( [TableName_NameAr] like ISNULL(@TableName_NameAr, [TableName_NameAr]) )
	AND ( [TableName_NameEn] like ISNULL(@TableName_NameEn, [TableName_NameEn]) )
	AND ( [TableName_Search] like ISNULL(@TableName_Search, [TableName_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users-Insert]    Script Date: [[20120714223943]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223943]]
-- Description:	Insert record into table [dbo].[Users]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users-Insert]
	/*@User_RowNumber int =Null OUTPUT , 
	@User_ID uniqueidentifier =Null  , 
	@User_NameAr varchar(200) =Null  , 
	@User_NameEn varchar(200) =Null  , 
	@User_LoginName varchar(200) =Null  , 
	@User_Password varchar(100) =Null  , 
	@User_Email varchar(100) =Null  , 
	@User_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Users](/*[User_ID], [User_NameAr], [User_NameEn], [User_LoginName], [User_Password], [User_Email], [User_Search]*/)
	VALUES     (/*@User_ID, @User_NameAr, @User_NameEn, @User_LoginName, @User_Password, @User_Email, @User_Search*/)

	/*SELECT @User_RowNumber = [User_RowNumber]
    FROM [dbo].[Users]
    WHERE  ( [User_ID] =@User_ID )
	AND  ( [User_NameAr] =@User_NameAr )
	AND  ( [User_NameEn] =@User_NameEn )
	AND  ( [User_LoginName] =@User_LoginName )
	AND  ( [User_Password] =@User_Password )
	AND  ( [User_Email] =@User_Email )
	AND  ( [User_Search] =@User_Search )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users-update]    Script Date: [[20120714223943]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223943]]
-- Description:	Update record in table [dbo].[Users]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users-update]
	/*@User_RowNumber int =Null OUTPUT , 
	@User_ID uniqueidentifier =Null  , 
	@User_NameAr varchar(200) =Null  , 
	@User_NameEn varchar(200) =Null  , 
	@User_LoginName varchar(200) =Null  , 
	@User_Password varchar(100) =Null  , 
	@User_Email varchar(100) =Null  , 
	@User_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Users] SET 
		/*[User_ID] =@User_ID, 
		[User_NameAr] =@User_NameAr, 
		[User_NameEn] =@User_NameEn, 
		[User_LoginName] =@User_LoginName, 
		[User_Password] =@User_Password, 
		[User_Email] =@User_Email, 
		[User_Search] =@User_Search*/
		/*WHERE ([User_ID] = @User_ID)*/
	/**/

	/*SELECT @User_RowNumber = [User_RowNumber]
    FROM [dbo].[Users]
	WHERE ([User_ID] = @User_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users-Insert-Update]    Script Date: [[20120714223943]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223943]]
-- Description:	Insert OR Update record into table [dbo].[Users]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users-Insert-Update]
	/*@User_RowNumber int =Null OUTPUT , 
	@User_ID uniqueidentifier =Null  , 
	@User_NameAr varchar(200) =Null  , 
	@User_NameEn varchar(200) =Null  , 
	@User_LoginName varchar(200) =Null  , 
	@User_Password varchar(100) =Null  , 
	@User_Email varchar(100) =Null  , 
	@User_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Users] 
					/*WHERE ([User_ID] = @User_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Users](/*[User_ID], [User_NameAr], [User_NameEn], [User_LoginName], [User_Password], [User_Email], [User_Search]*/)
		VALUES     (/*@User_ID, @User_NameAr, @User_NameEn, @User_LoginName, @User_Password, @User_Email, @User_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Users] SET 
			/*[User_ID] =@User_ID, 
			[User_NameAr] =@User_NameAr, 
			[User_NameEn] =@User_NameEn, 
			[User_LoginName] =@User_LoginName, 
			[User_Password] =@User_Password, 
			[User_Email] =@User_Email, 
			[User_Search] =@User_Search*/
			/*WHERE ([User_ID] = @User_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @User_RowNumber = [User_RowNumber]
    FROM [dbo].[Users]
	WHERE ([User_ID] = @User_ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users-Delete]    Script Date: [[20120714223943]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223943]]
-- Description:	delete records from table [dbo].[Users] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users-Delete]
	/*@User_RowNumber int =null  , 
	@User_ID uniqueidentifier =null  , 
	@User_NameAr varchar(200) =null  , 
	@User_NameEn varchar(200) =null  , 
	@User_LoginName varchar(200) =null  , 
	@User_Password varchar(100) =null  , 
	@User_Email varchar(100) =null  , 
	@User_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Users]
	WHERE /*( [User_RowNumber] = ISNULL(@User_RowNumber, [User_RowNumber]) )
	AND ( [User_ID] = ISNULL(@User_ID, [User_ID]) )
	AND ( [User_NameAr] like ISNULL(@User_NameAr, [User_NameAr]) )
	AND ( [User_NameEn] like ISNULL(@User_NameEn, [User_NameEn]) )
	AND ( [User_LoginName] like ISNULL(@User_LoginName, [User_LoginName]) )
	AND ( [User_Password] like ISNULL(@User_Password, [User_Password]) )
	AND ( [User_Email] like ISNULL(@User_Email, [User_Email]) )
	AND ( [User_Search] like ISNULL(@User_Search, [User_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users-Select]    Script Date: [[20120714223943]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223943]]
-- Description:	select records from table [dbo].[Users] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users-Select]
	/*@User_RowNumber int =null  , 
	@User_ID uniqueidentifier =null  , 
	@User_NameAr varchar(200) =null  , 
	@User_NameEn varchar(200) =null  , 
	@User_LoginName varchar(200) =null  , 
	@User_Password varchar(100) =null  , 
	@User_Email varchar(100) =null  , 
	@User_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Users]
	WHERE /*( [User_RowNumber] = ISNULL(@User_RowNumber, [User_RowNumber]) )
	AND ( [User_ID] = ISNULL(@User_ID, [User_ID]) )
	AND ( [User_NameAr] like ISNULL(@User_NameAr, [User_NameAr]) )
	AND ( [User_NameEn] like ISNULL(@User_NameEn, [User_NameEn]) )
	AND ( [User_LoginName] like ISNULL(@User_LoginName, [User_LoginName]) )
	AND ( [User_Password] like ISNULL(@User_Password, [User_Password]) )
	AND ( [User_Email] like ISNULL(@User_Email, [User_Email]) )
	AND ( [User_Search] like ISNULL(@User_Search, [User_Search]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users_Groups-Insert]    Script Date: [[20120714223943]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223943]]
-- Description:	Insert record into table [dbo].[Users_Groups]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users_Groups-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users_Groups-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users_Groups-Insert]
	/*@RowNumber int =Null  , 
	@ID uniqueidentifier =Null  , 
	@User_ID uniqueidentifier =Null  , 
	@Group_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Users_Groups](/*[RowNumber], [ID], [User_ID], [Group_ID]*/)
	VALUES     (/*@RowNumber, @ID, @User_ID, @Group_ID*/)

	/**/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users_Groups-update]    Script Date: [[20120714223943]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223943]]
-- Description:	Update record in table [dbo].[Users_Groups]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users_Groups-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users_Groups-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users_Groups-update]
	/*@RowNumber int =Null  , 
	@ID uniqueidentifier =Null  , 
	@User_ID uniqueidentifier =Null  , 
	@Group_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Users_Groups] SET 
		/*[RowNumber] =@RowNumber, 
		[ID] =@ID, 
		[User_ID] =@User_ID, 
		[Group_ID] =@Group_ID*/
		/*WHERE ([ID] = @ID)*/
	/**/

	/**/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users_Groups-Insert-Update]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	Insert OR Update record into table [dbo].[Users_Groups]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users_Groups-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users_Groups-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users_Groups-Insert-Update]
	/*@RowNumber int =Null  , 
	@ID uniqueidentifier =Null  , 
	@User_ID uniqueidentifier =Null  , 
	@Group_ID uniqueidentifier =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Users_Groups] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Users_Groups](/*[RowNumber], [ID], [User_ID], [Group_ID]*/)
		VALUES     (/*@RowNumber, @ID, @User_ID, @Group_ID*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Users_Groups] SET 
			/*[RowNumber] =@RowNumber, 
			[ID] =@ID, 
			[User_ID] =@User_ID, 
			[Group_ID] =@Group_ID*/
			/*WHERE ([ID] = @ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/**/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users_Groups-Delete]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	delete records from table [dbo].[Users_Groups] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users_Groups-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users_Groups-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users_Groups-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@User_ID uniqueidentifier =null  , 
	@Group_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Users_Groups]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [User_ID] = ISNULL(@User_ID, [User_ID]) )
	AND ( [Group_ID] = ISNULL(@Group_ID, [Group_ID]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users_Groups-Select]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	select records from table [dbo].[Users_Groups] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users_Groups-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users_Groups-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users_Groups-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@User_ID uniqueidentifier =null  , 
	@Group_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Users_Groups]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [User_ID] = ISNULL(@User_ID, [User_ID]) )
	AND ( [Group_ID] = ISNULL(@Group_ID, [Group_ID]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[UsersLogs-Insert]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	Insert record into table [dbo].[UsersLogs]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[UsersLogs-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[UsersLogs-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[UsersLogs-Insert]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@User_ID uniqueidentifier =Null  , 
	@Date datetime =Null  , 
	@Table_ID uniqueidentifier =Null  , 
	@Event_ID uniqueidentifier =Null  , 
	@Item_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[UsersLogs](/*[ID], [User_ID], [Date], [Table_ID], [Event_ID], [Item_ID]*/)
	VALUES     (/*@ID, @User_ID, @Date, @Table_ID, @Event_ID, @Item_ID*/)

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[UsersLogs]
    WHERE  ( [ID] =@ID )
	AND  ( [User_ID] =@User_ID )
	AND  ( [Date] =@Date )
	AND  ( [Table_ID] =@Table_ID )
	AND  ( [Event_ID] =@Event_ID )
	AND  ( [Item_ID] =@Item_ID )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[UsersLogs-update]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	Update record in table [dbo].[UsersLogs]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[UsersLogs-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[UsersLogs-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[UsersLogs-update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@User_ID uniqueidentifier =Null  , 
	@Date datetime =Null  , 
	@Table_ID uniqueidentifier =Null  , 
	@Event_ID uniqueidentifier =Null  , 
	@Item_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[UsersLogs] SET 
		/*[ID] =@ID, 
		[User_ID] =@User_ID, 
		[Date] =@Date, 
		[Table_ID] =@Table_ID, 
		[Event_ID] =@Event_ID, 
		[Item_ID] =@Item_ID*/
		/*WHERE ([ID] = @ID)*/
	/**/

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[UsersLogs]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[UsersLogs-Insert-Update]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	Insert OR Update record into table [dbo].[UsersLogs]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[UsersLogs-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[UsersLogs-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[UsersLogs-Insert-Update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@User_ID uniqueidentifier =Null  , 
	@Date datetime =Null  , 
	@Table_ID uniqueidentifier =Null  , 
	@Event_ID uniqueidentifier =Null  , 
	@Item_ID uniqueidentifier =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[UsersLogs] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[UsersLogs](/*[ID], [User_ID], [Date], [Table_ID], [Event_ID], [Item_ID]*/)
		VALUES     (/*@ID, @User_ID, @Date, @Table_ID, @Event_ID, @Item_ID*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[UsersLogs] SET 
			/*[ID] =@ID, 
			[User_ID] =@User_ID, 
			[Date] =@Date, 
			[Table_ID] =@Table_ID, 
			[Event_ID] =@Event_ID, 
			[Item_ID] =@Item_ID*/
			/*WHERE ([ID] = @ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[UsersLogs]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[UsersLogs-Delete]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	delete records from table [dbo].[UsersLogs] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[UsersLogs-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[UsersLogs-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[UsersLogs-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@User_ID uniqueidentifier =null  , 
	@Date datetime =null  , 
	@Table_ID uniqueidentifier =null  , 
	@Event_ID uniqueidentifier =null  , 
	@Item_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[UsersLogs]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [User_ID] = ISNULL(@User_ID, [User_ID]) )
	AND ( [Date] = ISNULL(@Date, [Date]) )
	AND ( [Table_ID] = ISNULL(@Table_ID, [Table_ID]) )
	AND ( [Event_ID] = ISNULL(@Event_ID, [Event_ID]) )
	AND ( [Item_ID] = ISNULL(@Item_ID, [Item_ID]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[UsersLogs-Select]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	select records from table [dbo].[UsersLogs] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[UsersLogs-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[UsersLogs-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[UsersLogs-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@User_ID uniqueidentifier =null  , 
	@Date datetime =null  , 
	@Table_ID uniqueidentifier =null  , 
	@Event_ID uniqueidentifier =null  , 
	@Item_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[UsersLogs]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [User_ID] = ISNULL(@User_ID, [User_ID]) )
	AND ( [Date] = ISNULL(@Date, [Date]) )
	AND ( [Table_ID] = ISNULL(@Table_ID, [Table_ID]) )
	AND ( [Event_ID] = ISNULL(@Event_ID, [Event_ID]) )
	AND ( [Item_ID] = ISNULL(@Item_ID, [Item_ID]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[View_BDSP-Insert]    Script Date: [[20120714223945]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223945]]
-- Description:	Insert record into table [dbo].[View_BDSP]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[View_BDSP-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[View_BDSP-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[View_BDSP-Insert]
	/*@Bill_RowNumber int =Null  , 
	@Bill_ID uniqueidentifier =Null  , 
	@Bill_Code varchar(50) =Null  , 
	@BillType_ID uniqueidentifier =Null  , 
	@BillType_Code varchar(50) =Null  , 
	@BillType_NameAr varchar(300) =Null  , 
	@BillType_NameEn varchar(300) =Null  , 
	@DealerType_ID uniqueidentifier =Null  , 
	@DealerTypeCode varchar(50) =Null  , 
	@DealerType_NameAr varchar(300) =Null  , 
	@DealerType_NameEn varchar(300) =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Dealer_Code varchar(50) =Null  , 
	@Dealer_NameAr varchar(300) =Null  , 
	@Dealer_NameEn varchar(300) =Null  , 
	@BillDetail_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Code varchar(50) =Null  , 
	@Product_NameAr varchar(300) =Null  , 
	@Product_NameEn varchar(300) =Null  , 
	@Quantity float =Null  , 
	@Price float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@MeasureUnit_Code varchar(50) =Null  , 
	@MeasureUnit_NameAr varchar(300) =Null  , 
	@MeasureUnit_NameEn varchar(300) =Null  , 
	@Offer_ID uniqueidentifier =Null  , 
	@Offer_Notes varchar(max) =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Store_Code varchar(50) =Null  , 
	@Store_NameAr varchar(300) =Null  , 
	@Store_NameEn varchar(300) =Null  , 
	@Store_Address varchar(500) =Null  , 
	@IsSellPlace tinyint =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[View_BDSP](/*[Bill_RowNumber], [Bill_ID], [Bill_Code], [BillType_ID], [BillType_Code], [BillType_NameAr], [BillType_NameEn], [DealerType_ID], [DealerTypeCode], [DealerType_NameAr], [DealerType_NameEn], [Dealer_ID], [Dealer_Code], [Dealer_NameAr], [Dealer_NameEn], [BillDetail_ID], [Product_ID], [Product_Code], [Product_NameAr], [Product_NameEn], [Quantity], [Price], [MeasureUnit_ID], [MeasureUnit_Code], [MeasureUnit_NameAr], [MeasureUnit_NameEn], [Offer_ID], [Offer_Notes], [Store_ID], [Store_Code], [Store_NameAr], [Store_NameEn], [Store_Address], [IsSellPlace]*/)
	VALUES     (/*@Bill_RowNumber, @Bill_ID, @Bill_Code, @BillType_ID, @BillType_Code, @BillType_NameAr, @BillType_NameEn, @DealerType_ID, @DealerTypeCode, @DealerType_NameAr, @DealerType_NameEn, @Dealer_ID, @Dealer_Code, @Dealer_NameAr, @Dealer_NameEn, @BillDetail_ID, @Product_ID, @Product_Code, @Product_NameAr, @Product_NameEn, @Quantity, @Price, @MeasureUnit_ID, @MeasureUnit_Code, @MeasureUnit_NameAr, @MeasureUnit_NameEn, @Offer_ID, @Offer_Notes, @Store_ID, @Store_Code, @Store_NameAr, @Store_NameEn, @Store_Address, @IsSellPlace*/)

	/**/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[View_BDSP-update]    Script Date: [[20120714223945]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223945]]
-- Description:	Update record in table [dbo].[View_BDSP]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[View_BDSP-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[View_BDSP-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[View_BDSP-update]
	/*@Bill_RowNumber int =Null  , 
	@Bill_ID uniqueidentifier =Null  , 
	@Bill_Code varchar(50) =Null  , 
	@BillType_ID uniqueidentifier =Null  , 
	@BillType_Code varchar(50) =Null  , 
	@BillType_NameAr varchar(300) =Null  , 
	@BillType_NameEn varchar(300) =Null  , 
	@DealerType_ID uniqueidentifier =Null  , 
	@DealerTypeCode varchar(50) =Null  , 
	@DealerType_NameAr varchar(300) =Null  , 
	@DealerType_NameEn varchar(300) =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Dealer_Code varchar(50) =Null  , 
	@Dealer_NameAr varchar(300) =Null  , 
	@Dealer_NameEn varchar(300) =Null  , 
	@BillDetail_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Code varchar(50) =Null  , 
	@Product_NameAr varchar(300) =Null  , 
	@Product_NameEn varchar(300) =Null  , 
	@Quantity float =Null  , 
	@Price float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@MeasureUnit_Code varchar(50) =Null  , 
	@MeasureUnit_NameAr varchar(300) =Null  , 
	@MeasureUnit_NameEn varchar(300) =Null  , 
	@Offer_ID uniqueidentifier =Null  , 
	@Offer_Notes varchar(max) =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Store_Code varchar(50) =Null  , 
	@Store_NameAr varchar(300) =Null  , 
	@Store_NameEn varchar(300) =Null  , 
	@Store_Address varchar(500) =Null  , 
	@IsSellPlace tinyint =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[View_BDSP] SET 
		/*[Bill_RowNumber] =@Bill_RowNumber, 
		[Bill_ID] =@Bill_ID, 
		[Bill_Code] =@Bill_Code, 
		[BillType_ID] =@BillType_ID, 
		[BillType_Code] =@BillType_Code, 
		[BillType_NameAr] =@BillType_NameAr, 
		[BillType_NameEn] =@BillType_NameEn, 
		[DealerType_ID] =@DealerType_ID, 
		[DealerTypeCode] =@DealerTypeCode, 
		[DealerType_NameAr] =@DealerType_NameAr, 
		[DealerType_NameEn] =@DealerType_NameEn, 
		[Dealer_ID] =@Dealer_ID, 
		[Dealer_Code] =@Dealer_Code, 
		[Dealer_NameAr] =@Dealer_NameAr, 
		[Dealer_NameEn] =@Dealer_NameEn, 
		[BillDetail_ID] =@BillDetail_ID, 
		[Product_ID] =@Product_ID, 
		[Product_Code] =@Product_Code, 
		[Product_NameAr] =@Product_NameAr, 
		[Product_NameEn] =@Product_NameEn, 
		[Quantity] =@Quantity, 
		[Price] =@Price, 
		[MeasureUnit_ID] =@MeasureUnit_ID, 
		[MeasureUnit_Code] =@MeasureUnit_Code, 
		[MeasureUnit_NameAr] =@MeasureUnit_NameAr, 
		[MeasureUnit_NameEn] =@MeasureUnit_NameEn, 
		[Offer_ID] =@Offer_ID, 
		[Offer_Notes] =@Offer_Notes, 
		[Store_ID] =@Store_ID, 
		[Store_Code] =@Store_Code, 
		[Store_NameAr] =@Store_NameAr, 
		[Store_NameEn] =@Store_NameEn, 
		[Store_Address] =@Store_Address, 
		[IsSellPlace] =@IsSellPlace*/
		/**/
	/**/

	/**/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[View_BDSP-Insert-Update]    Script Date: [[20120714223945]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223945]]
-- Description:	Insert OR Update record into table [dbo].[View_BDSP]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[View_BDSP-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[View_BDSP-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[View_BDSP-Insert-Update]
	/*@Bill_RowNumber int =Null  , 
	@Bill_ID uniqueidentifier =Null  , 
	@Bill_Code varchar(50) =Null  , 
	@BillType_ID uniqueidentifier =Null  , 
	@BillType_Code varchar(50) =Null  , 
	@BillType_NameAr varchar(300) =Null  , 
	@BillType_NameEn varchar(300) =Null  , 
	@DealerType_ID uniqueidentifier =Null  , 
	@DealerTypeCode varchar(50) =Null  , 
	@DealerType_NameAr varchar(300) =Null  , 
	@DealerType_NameEn varchar(300) =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Dealer_Code varchar(50) =Null  , 
	@Dealer_NameAr varchar(300) =Null  , 
	@Dealer_NameEn varchar(300) =Null  , 
	@BillDetail_ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@Product_Code varchar(50) =Null  , 
	@Product_NameAr varchar(300) =Null  , 
	@Product_NameEn varchar(300) =Null  , 
	@Quantity float =Null  , 
	@Price float =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@MeasureUnit_Code varchar(50) =Null  , 
	@MeasureUnit_NameAr varchar(300) =Null  , 
	@MeasureUnit_NameEn varchar(300) =Null  , 
	@Offer_ID uniqueidentifier =Null  , 
	@Offer_Notes varchar(max) =Null  , 
	@Store_ID uniqueidentifier =Null  , 
	@Store_Code varchar(50) =Null  , 
	@Store_NameAr varchar(300) =Null  , 
	@Store_NameEn varchar(300) =Null  , 
	@Store_Address varchar(500) =Null  , 
	@IsSellPlace tinyint =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[View_BDSP] 
					/**/)
	BEGIN
		
		INSERT  INTO [dbo].[View_BDSP](/*[Bill_RowNumber], [Bill_ID], [Bill_Code], [BillType_ID], [BillType_Code], [BillType_NameAr], [BillType_NameEn], [DealerType_ID], [DealerTypeCode], [DealerType_NameAr], [DealerType_NameEn], [Dealer_ID], [Dealer_Code], [Dealer_NameAr], [Dealer_NameEn], [BillDetail_ID], [Product_ID], [Product_Code], [Product_NameAr], [Product_NameEn], [Quantity], [Price], [MeasureUnit_ID], [MeasureUnit_Code], [MeasureUnit_NameAr], [MeasureUnit_NameEn], [Offer_ID], [Offer_Notes], [Store_ID], [Store_Code], [Store_NameAr], [Store_NameEn], [Store_Address], [IsSellPlace]*/)
		VALUES     (/*@Bill_RowNumber, @Bill_ID, @Bill_Code, @BillType_ID, @BillType_Code, @BillType_NameAr, @BillType_NameEn, @DealerType_ID, @DealerTypeCode, @DealerType_NameAr, @DealerType_NameEn, @Dealer_ID, @Dealer_Code, @Dealer_NameAr, @Dealer_NameEn, @BillDetail_ID, @Product_ID, @Product_Code, @Product_NameAr, @Product_NameEn, @Quantity, @Price, @MeasureUnit_ID, @MeasureUnit_Code, @MeasureUnit_NameAr, @MeasureUnit_NameEn, @Offer_ID, @Offer_Notes, @Store_ID, @Store_Code, @Store_NameAr, @Store_NameEn, @Store_Address, @IsSellPlace*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[View_BDSP] SET 
			/*[Bill_RowNumber] =@Bill_RowNumber, 
			[Bill_ID] =@Bill_ID, 
			[Bill_Code] =@Bill_Code, 
			[BillType_ID] =@BillType_ID, 
			[BillType_Code] =@BillType_Code, 
			[BillType_NameAr] =@BillType_NameAr, 
			[BillType_NameEn] =@BillType_NameEn, 
			[DealerType_ID] =@DealerType_ID, 
			[DealerTypeCode] =@DealerTypeCode, 
			[DealerType_NameAr] =@DealerType_NameAr, 
			[DealerType_NameEn] =@DealerType_NameEn, 
			[Dealer_ID] =@Dealer_ID, 
			[Dealer_Code] =@Dealer_Code, 
			[Dealer_NameAr] =@Dealer_NameAr, 
			[Dealer_NameEn] =@Dealer_NameEn, 
			[BillDetail_ID] =@BillDetail_ID, 
			[Product_ID] =@Product_ID, 
			[Product_Code] =@Product_Code, 
			[Product_NameAr] =@Product_NameAr, 
			[Product_NameEn] =@Product_NameEn, 
			[Quantity] =@Quantity, 
			[Price] =@Price, 
			[MeasureUnit_ID] =@MeasureUnit_ID, 
			[MeasureUnit_Code] =@MeasureUnit_Code, 
			[MeasureUnit_NameAr] =@MeasureUnit_NameAr, 
			[MeasureUnit_NameEn] =@MeasureUnit_NameEn, 
			[Offer_ID] =@Offer_ID, 
			[Offer_Notes] =@Offer_Notes, 
			[Store_ID] =@Store_ID, 
			[Store_Code] =@Store_Code, 
			[Store_NameAr] =@Store_NameAr, 
			[Store_NameEn] =@Store_NameEn, 
			[Store_Address] =@Store_Address, 
			[IsSellPlace] =@IsSellPlace*/
			/**/
		/**/
		
		SET /*@*/Inserted=0
	END

	/**/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[View_BDSP-Delete]    Script Date: [[20120714223945]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223945]]
-- Description:	delete records from table [dbo].[View_BDSP] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[View_BDSP-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[View_BDSP-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[View_BDSP-Delete]
	/*@Bill_RowNumber int =null  , 
	@Bill_ID uniqueidentifier =null  , 
	@Bill_Code varchar(50) =null  , 
	@BillType_ID uniqueidentifier =null  , 
	@BillType_Code varchar(50) =null  , 
	@BillType_NameAr varchar(300) =null  , 
	@BillType_NameEn varchar(300) =null  , 
	@DealerType_ID uniqueidentifier =null  , 
	@DealerTypeCode varchar(50) =null  , 
	@DealerType_NameAr varchar(300) =null  , 
	@DealerType_NameEn varchar(300) =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Dealer_Code varchar(50) =null  , 
	@Dealer_NameAr varchar(300) =null  , 
	@Dealer_NameEn varchar(300) =null  , 
	@BillDetail_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Product_Code varchar(50) =null  , 
	@Product_NameAr varchar(300) =null  , 
	@Product_NameEn varchar(300) =null  , 
	@Quantity float =null  , 
	@Price float =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@MeasureUnit_Code varchar(50) =null  , 
	@MeasureUnit_NameAr varchar(300) =null  , 
	@MeasureUnit_NameEn varchar(300) =null  , 
	@Offer_ID uniqueidentifier =null  , 
	@Offer_Notes varchar(max) =null  , 
	@Store_ID uniqueidentifier =null  , 
	@Store_Code varchar(50) =null  , 
	@Store_NameAr varchar(300) =null  , 
	@Store_NameEn varchar(300) =null  , 
	@Store_Address varchar(500) =null  , 
	@IsSellPlace tinyint =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[View_BDSP]
	WHERE /*( [Bill_RowNumber] = ISNULL(@Bill_RowNumber, [Bill_RowNumber]) )
	AND ( [Bill_ID] = ISNULL(@Bill_ID, [Bill_ID]) )
	AND ( [Bill_Code] like ISNULL(@Bill_Code, [Bill_Code]) )
	AND ( [BillType_ID] = ISNULL(@BillType_ID, [BillType_ID]) )
	AND ( [BillType_Code] like ISNULL(@BillType_Code, [BillType_Code]) )
	AND ( [BillType_NameAr] like ISNULL(@BillType_NameAr, [BillType_NameAr]) )
	AND ( [BillType_NameEn] like ISNULL(@BillType_NameEn, [BillType_NameEn]) )
	AND ( [DealerType_ID] = ISNULL(@DealerType_ID, [DealerType_ID]) )
	AND ( [DealerTypeCode] like ISNULL(@DealerTypeCode, [DealerTypeCode]) )
	AND ( [DealerType_NameAr] like ISNULL(@DealerType_NameAr, [DealerType_NameAr]) )
	AND ( [DealerType_NameEn] like ISNULL(@DealerType_NameEn, [DealerType_NameEn]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Dealer_Code] like ISNULL(@Dealer_Code, [Dealer_Code]) )
	AND ( [Dealer_NameAr] like ISNULL(@Dealer_NameAr, [Dealer_NameAr]) )
	AND ( [Dealer_NameEn] like ISNULL(@Dealer_NameEn, [Dealer_NameEn]) )
	AND ( [BillDetail_ID] = ISNULL(@BillDetail_ID, [BillDetail_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Product_Code] like ISNULL(@Product_Code, [Product_Code]) )
	AND ( [Product_NameAr] like ISNULL(@Product_NameAr, [Product_NameAr]) )
	AND ( [Product_NameEn] like ISNULL(@Product_NameEn, [Product_NameEn]) )
	AND ( [Quantity] = ISNULL(@Quantity, [Quantity]) )
	AND ( [Price] = ISNULL(@Price, [Price]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [MeasureUnit_Code] like ISNULL(@MeasureUnit_Code, [MeasureUnit_Code]) )
	AND ( [MeasureUnit_NameAr] like ISNULL(@MeasureUnit_NameAr, [MeasureUnit_NameAr]) )
	AND ( [MeasureUnit_NameEn] like ISNULL(@MeasureUnit_NameEn, [MeasureUnit_NameEn]) )
	AND ( [Offer_ID] = ISNULL(@Offer_ID, [Offer_ID]) )
	AND ( [Offer_Notes] like ISNULL(@Offer_Notes, [Offer_Notes]) )
	AND ( [Store_ID] = ISNULL(@Store_ID, [Store_ID]) )
	AND ( [Store_Code] like ISNULL(@Store_Code, [Store_Code]) )
	AND ( [Store_NameAr] like ISNULL(@Store_NameAr, [Store_NameAr]) )
	AND ( [Store_NameEn] like ISNULL(@Store_NameEn, [Store_NameEn]) )
	AND ( [Store_Address] like ISNULL(@Store_Address, [Store_Address]) )
	AND ( [IsSellPlace] = ISNULL(@IsSellPlace, [IsSellPlace]) )*/
END
GO
-- =============================================



--USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[View_BDSP-Select]    Script Date: [[20120714223945]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223945]]
-- Description:	select records from table [dbo].[View_BDSP] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[View_BDSP-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[View_BDSP-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[View_BDSP-Select]
	/*@Bill_RowNumber int =null  , 
	@Bill_ID uniqueidentifier =null  , 
	@Bill_Code varchar(50) =null  , 
	@BillType_ID uniqueidentifier =null  , 
	@BillType_Code varchar(50) =null  , 
	@BillType_NameAr varchar(300) =null  , 
	@BillType_NameEn varchar(300) =null  , 
	@DealerType_ID uniqueidentifier =null  , 
	@DealerTypeCode varchar(50) =null  , 
	@DealerType_NameAr varchar(300) =null  , 
	@DealerType_NameEn varchar(300) =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Dealer_Code varchar(50) =null  , 
	@Dealer_NameAr varchar(300) =null  , 
	@Dealer_NameEn varchar(300) =null  , 
	@BillDetail_ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@Product_Code varchar(50) =null  , 
	@Product_NameAr varchar(300) =null  , 
	@Product_NameEn varchar(300) =null  , 
	@Quantity float =null  , 
	@Price float =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@MeasureUnit_Code varchar(50) =null  , 
	@MeasureUnit_NameAr varchar(300) =null  , 
	@MeasureUnit_NameEn varchar(300) =null  , 
	@Offer_ID uniqueidentifier =null  , 
	@Offer_Notes varchar(max) =null  , 
	@Store_ID uniqueidentifier =null  , 
	@Store_Code varchar(50) =null  , 
	@Store_NameAr varchar(300) =null  , 
	@Store_NameEn varchar(300) =null  , 
	@Store_Address varchar(500) =null  , 
	@IsSellPlace tinyint =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[View_BDSP]
	WHERE /*( [Bill_RowNumber] = ISNULL(@Bill_RowNumber, [Bill_RowNumber]) )
	AND ( [Bill_ID] = ISNULL(@Bill_ID, [Bill_ID]) )
	AND ( [Bill_Code] like ISNULL(@Bill_Code, [Bill_Code]) )
	AND ( [BillType_ID] = ISNULL(@BillType_ID, [BillType_ID]) )
	AND ( [BillType_Code] like ISNULL(@BillType_Code, [BillType_Code]) )
	AND ( [BillType_NameAr] like ISNULL(@BillType_NameAr, [BillType_NameAr]) )
	AND ( [BillType_NameEn] like ISNULL(@BillType_NameEn, [BillType_NameEn]) )
	AND ( [DealerType_ID] = ISNULL(@DealerType_ID, [DealerType_ID]) )
	AND ( [DealerTypeCode] like ISNULL(@DealerTypeCode, [DealerTypeCode]) )
	AND ( [DealerType_NameAr] like ISNULL(@DealerType_NameAr, [DealerType_NameAr]) )
	AND ( [DealerType_NameEn] like ISNULL(@DealerType_NameEn, [DealerType_NameEn]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Dealer_Code] like ISNULL(@Dealer_Code, [Dealer_Code]) )
	AND ( [Dealer_NameAr] like ISNULL(@Dealer_NameAr, [Dealer_NameAr]) )
	AND ( [Dealer_NameEn] like ISNULL(@Dealer_NameEn, [Dealer_NameEn]) )
	AND ( [BillDetail_ID] = ISNULL(@BillDetail_ID, [BillDetail_ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [Product_Code] like ISNULL(@Product_Code, [Product_Code]) )
	AND ( [Product_NameAr] like ISNULL(@Product_NameAr, [Product_NameAr]) )
	AND ( [Product_NameEn] like ISNULL(@Product_NameEn, [Product_NameEn]) )
	AND ( [Quantity] = ISNULL(@Quantity, [Quantity]) )
	AND ( [Price] = ISNULL(@Price, [Price]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [MeasureUnit_Code] like ISNULL(@MeasureUnit_Code, [MeasureUnit_Code]) )
	AND ( [MeasureUnit_NameAr] like ISNULL(@MeasureUnit_NameAr, [MeasureUnit_NameAr]) )
	AND ( [MeasureUnit_NameEn] like ISNULL(@MeasureUnit_NameEn, [MeasureUnit_NameEn]) )
	AND ( [Offer_ID] = ISNULL(@Offer_ID, [Offer_ID]) )
	AND ( [Offer_Notes] like ISNULL(@Offer_Notes, [Offer_Notes]) )
	AND ( [Store_ID] = ISNULL(@Store_ID, [Store_ID]) )
	AND ( [Store_Code] like ISNULL(@Store_Code, [Store_Code]) )
	AND ( [Store_NameAr] like ISNULL(@Store_NameAr, [Store_NameAr]) )
	AND ( [Store_NameEn] like ISNULL(@Store_NameEn, [Store_NameEn]) )
	AND ( [Store_Address] like ISNULL(@Store_Address, [Store_Address]) )
	AND ( [IsSellPlace] = ISNULL(@IsSellPlace, [IsSellPlace]) )*/
END
GO
-- =============================================
